/**
  * testing the is_messenger_active() method
  *
  * @since 4.4.1
  */
 public function test_is_messenger_active()
 {
     //test messenger that should be active
     EE_Registry::instance()->load_helper('MSG_Template');
     $this->assertTrue(EEH_MSG_Template::is_messenger_active('email'));
     //test messenger that should NOT be active
     $this->assertFalse(EEH_MSG_Template::is_messenger_active('some_random_messenger'));
 }
 /**
  * tests to make sure forcing a messenger to be active works.
  *
  * @since 4.5.0
  */
 public function test_ensure_messenger_is_active()
 {
     EE_Registry::instance()->load_lib('messages');
     EE_Registry::instance()->load_helper('Activation');
     $msg = new EE_messages();
     $this->assertInstanceOf('EE_messages', $msg);
     //make sure html messenger is setup (should be by default)
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     $this->assertTrue(isset($active_messengers['html']), sprintf('The messenger %s should be active on fresh install, but it is not.', 'html'));
     //let's UNSET the html messenger from active messengers and update the db
     unset($active_messengers['html']);
     EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
     //now let's FORCE reactivation.
     $response = $msg->ensure_messenger_is_active('html');
     $this->assertFalse($response);
     //that means it was previously inactive which it should be.
     //verify html messenger IS actually active now.
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     $this->assertTrue(isset($active_messengers['html']), 'The html messenger should have been forced to be active again but it is not.');
     //now verify that trying to ensure is active verifies it's already active
     $response = $msg->ensure_messenger_is_active('html');
     $this->assertTrue($response);
 }
 /**
  * This returns the specific template pack object referenced by the template pack name attached to this message template group.  If no template pack is assigned then the default template pack is retrieved.
  *
  * @since 4.5.0
  *
  * @return EE_Messages_Template_Pack
  */
 public function get_template_pack()
 {
     $pack_name = $this->get_template_pack_name();
     EE_Registry::instance()->load_helper('MSG_Template');
     return EEH_MSG_Template::get_template_pack($pack_name);
 }
 /**
  * This will activate and generate default messengers and default message types for those messengers.
  *
  * @param EE_message_Resource_Manager $message_resource_manager
  * @return array|bool  True means there were default messengers and message type templates generated.
  *                     False means that there were no templates generated
  *                     (which could simply mean there are no default message types for a messenger).
  * @throws EE_Error
  */
 protected static function _activate_and_generate_default_messengers_and_message_templates(EE_Message_Resource_Manager $message_resource_manager)
 {
     /** @type EE_messenger[] $messengers_to_generate */
     $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
     $installed_message_types = $message_resource_manager->installed_message_types();
     $templates_generated = false;
     foreach ($messengers_to_generate as $messenger_to_generate) {
         $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
         //verify the default message types match an installed message type.
         foreach ($default_message_type_names_for_messenger as $key => $name) {
             if (!isset($installed_message_types[$name]) || $message_resource_manager->has_message_type_been_activated_for_messenger($name, $messenger_to_generate->name)) {
                 unset($default_message_type_names_for_messenger[$key]);
             }
         }
         // in previous iterations, the active_messengers option in the db
         // needed updated before calling create templates. however with the changes this may not be necessary.
         // This comment is left here just in case we discover that we _do_ need to update before
         // passing off to create templates (after the refactor is done).
         // @todo remove this comment when determined not necessary.
         $message_resource_manager->activate_messenger($messenger_to_generate->name, $default_message_type_names_for_messenger, false);
         //create any templates needing created (or will reactivate templates already generated as necessary).
         if (!empty($default_message_type_names_for_messenger)) {
             $templates_generated = EEH_MSG_Template::generate_new_templates($messenger_to_generate->name, $default_message_type_names_for_messenger, '', true);
         }
     }
     return $templates_generated;
 }
 /**
  * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send trigger
  *
  * @since   4.3.0
  *
  * @param 	string 	$registration_message_trigger_url
  * @param 	EE_Registration $registration
  * @param string 	$messenger
  * @param string 	$message_type
  * @return 	string
  */
 public static function registration_message_trigger_url($registration_message_trigger_url, EE_Registration $registration, $messenger = 'html', $message_type = 'invoice')
 {
     EE_Registry::instance()->load_helper('MSG_Template');
     // whitelist $messenger
     switch ($messenger) {
         case 'pdf':
             $sending_messenger = 'pdf';
             $generating_messenger = 'html';
             break;
         case 'html':
         default:
             $sending_messenger = 'html';
             $generating_messenger = 'html';
             break;
     }
     // whitelist $message_type
     switch ($message_type) {
         case 'receipt':
             $message_type = 'receipt';
             break;
         case 'invoice':
         default:
             $message_type = 'invoice';
             break;
     }
     // verify that both the messenger AND the message type are active
     if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
         //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
         $template_query_params = array('MTP_is_active' => TRUE, 'MTP_messenger' => $generating_messenger, 'MTP_message_type' => $message_type, 'Event.EVT_ID' => $registration->event_ID());
         //get the message template group.
         $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
         //if we don't have an EE_Message_Template_Group then return
         if (!$msg_template_group instanceof EE_Message_Template_Group) {
             // remove EVT_ID from query params so that global templates get picked up
             unset($template_query_params['Event.EVT_ID']);
             //get global template as the fallback
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
         }
         //if we don't have an EE_Message_Template_Group then return
         if (!$msg_template_group instanceof EE_Message_Template_Group) {
             return '';
         }
         // generate the URL
         $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger($sending_messenger, $generating_messenger, 'purchaser', $message_type, $registration, $msg_template_group->ID(), $registration->transaction_ID());
     }
     return $registration_message_trigger_url;
 }
 /**
  * This method checks for registration IDs in the request via the given key and creates the messages to generate
  * objects from them, then returns the array of messages to generate objects.
  * Note, this sets up registrations for the registration family of message types.
  *
  * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
  *
  * @return EE_Message_To_Generate[]
  */
 public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID')
 {
     EE_Registry::instance()->load_core('Request_Handler');
     EE_Registry::instance()->load_helper('MSG_Template');
     $regs_to_send = array();
     $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key);
     if (empty($regIDs)) {
         EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     //make sure is an array
     $regIDs = is_array($regIDs) ? $regIDs : array($regIDs);
     foreach ($regIDs as $regID) {
         $reg = EEM_Registration::instance()->get_one_by_ID($regID);
         if (!$reg instanceof EE_Registration) {
             EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID));
             return false;
         }
         $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
     }
     $messages_to_generate = array();
     foreach ($regs_to_send as $status_group) {
         foreach ($status_group as $status_id => $registrations) {
             $messages_to_generate = array_merge($messages_to_generate, $this->setup_mtgs_for_all_active_messengers(EEH_MSG_Template::convert_reg_status_to_message_type($status_id), array($registrations, $status_id)));
         }
     }
     return $messages_to_generate;
 }
 /**
  * All this does is set the existing test settings (in the db) for the messenger
  *
  * @access public
  * @return bool 	success/fail
  */
 public function set_existing_test_settings($settings)
 {
     $existing = EEH_MSG_Template::get_active_messengers_in_db();
     $existing[$this->name]['test_settings'] = $settings;
     return EEH_MSG_Template::update_active_messengers_in_db($existing);
 }
 /**
  * @param EE_Message $message
  * @return string   Actions that can be done on the current message.
  */
 public function column_action(EE_Message $message)
 {
     EE_Registry::instance()->load_helper('MSG_Template');
     $action_links = array('view' => EEH_MSG_Template::get_message_action_link('view', $message), 'error' => EEH_MSG_Template::get_message_action_link('error', $message), 'generate_now' => EEH_MSG_Template::get_message_action_link('generate_now', $message), 'send_now' => EEH_MSG_Template::get_message_action_link('send_now', $message), 'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message), 'view_transaction' => EEH_MSG_Template::get_message_action_link('view_transaction', $message));
     $content = '';
     switch ($message->STS_ID()) {
         case EEM_Message::status_sent:
             $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
             break;
         case EEM_Message::status_resend:
             $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
             break;
         case EEM_Message::status_retry:
             $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
             break;
         case EEM_Message::status_failed:
         case EEM_Message::status_debug_only:
             $content = $action_links['error'] . $action_links['view_transaction'];
             break;
         case EEM_Message::status_idle:
             $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
             break;
         case EEM_Message::status_incomplete:
             $content = $action_links['generate_now'] . $action_links['view_transaction'];
             break;
     }
     return $content;
 }
 /**
  * 		generates HTML for the View Transaction Details Admin page
  *		@access protected
  *		@return void
  */
 protected function _transaction_details()
 {
     $this->_get_transaction_status_array();
     $this->_template_args = array();
     $this->_template_args['transactions_page'] = $this->wp_page_slug;
     $this->_set_transaction_object();
     $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
     $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso');
     $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_datetime('TXN_timestamp', 'l F j, Y', 'g:i:s a');
     $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso');
     $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
     $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso');
     $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
     $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
     $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
     EE_Registry::instance()->load_helper('MSG_Template');
     $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
     $this->_template_args['amount_due'] = ' <span id="txn-admin-total-amount-due">' . EEH_Template::format_currency($amount_due, TRUE) . '</span>';
     if (EE_Registry::instance()->CFG->currency->sign_b4) {
         $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
     } else {
         $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
     }
     $this->_template_args['amount_due_class'] = '';
     if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
         // paid in full
         $this->_template_args['amount_due'] = FALSE;
     } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
         // overpaid
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') > 0) {
         // monies owing
         $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') == 0) {
         // no payments made yet
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') == 0) {
         // free event
         $this->_template_args['amount_due'] = FALSE;
     }
     $gateway = $this->_transaction->get_extra_meta('gateway', true, FALSE);
     $this->_template_args['method_of_payment'] = $gateway;
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     // link back to overview
     $this->_template_args['txn_overview_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL;
     // grab messages at the last second
     $this->_template_args['notices'] = EE_Error::get_notices();
     // path to template
     $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
     $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE);
     // the details template wrapper
     $this->display_admin_page_with_sidebar();
 }
 /**
  * This method takes the incoming data and figures out from it what the message type is and
  * evt_id/grp_id and uses that to generate the url for displaying the template in a browser.
  *
  * @since 4.5.0
  *
  * @param EE_Messages_Addressee $recipient
  * @param string $sending_messenger
  *
  * @return string The generated url for displaying the link.
  * @throws EE_Error
  */
 private function _get_url(EE_Messages_Addressee $recipient, $sending_messenger)
 {
     $reg = $recipient->reg_obj;
     $reg = !$reg instanceof EE_Registration ? $recipient->primary_reg_obj : $reg;
     if ($this->_message_type instanceof EE_message_type && $this->_message instanceof EE_Message) {
         EE_Registry::instance()->load_helper('MSG_Template');
         try {
             return EEH_MSG_Template::get_url_trigger($this->_message_type, $this->_message, $reg, $sending_messenger);
         } catch (EE_Error $e) {
             if (WP_DEBUG) {
                 $e->get_error();
             }
         }
     }
     return '';
 }
 /**
  * Return the link to the admin details for the object.
  * @return string
  */
 public function get_admin_details_link()
 {
     EE_Registry::instance()->load_helper('URL');
     EE_Registry::instance()->load_helper('MSG_Template');
     switch ($this->STS_ID()) {
         case EEM_Message::status_failed:
         case EEM_Message::status_debug_only:
             return EEH_MSG_Template::generate_error_display_trigger($this);
             break;
         case EEM_Message::status_sent:
             return EEH_MSG_Template::generate_browser_trigger($this);
             break;
         default:
             return '';
     }
 }
 public function additional_legend_items($items)
 {
     if (EE_Registry::instance()->CAP->current_user_can('ee_read_registrations', 'espresso_registrations_reports')) {
         $items['reports'] = array('class' => 'dashicons dashicons-chart-bar', 'desc' => __('Event Reports', 'event_espresso'));
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
         $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
         if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
             $items['view_related_messages'] = array('class' => $related_for_icon['css_class'], 'desc' => $related_for_icon['label']);
         }
     }
     return $items;
 }
 /**
  * This deregisters a message type that was previously registered with a specific mtname.
  *
  * @since    4.3.0
  *
  * @param string  $mt_name the name for the message type that was previously registered
  * @return void
  */
 public static function deregister($mt_name = NULL)
 {
     if (!empty(self::$_ee_message_type_registry[$mt_name])) {
         //let's make sure that we remove any place this message type was made active
         EE_Registry::instance()->load_helper('MSG_Template');
         $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
         foreach ($active_messengers as $messenger => $settings) {
             if (!empty($settings['settings'][$messenger . '-message_types'][$mt_name])) {
                 unset($active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt_name]);
             }
         }
         EEH_MSG_Template::update_to_inactive('', $mt_name);
         EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
         unset(self::$_ee_message_type_registry[$mt_name]);
     }
 }
 /**
  * 	_transaction_details
  * generates HTML for the View Transaction Details Admin page
  *
  * @access protected
  *	@return void
  */
 protected function _transaction_details()
 {
     do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
     $this->_set_transaction_status_array();
     $this->_template_args = array();
     $this->_template_args['transactions_page'] = $this->_wp_page_slug;
     $this->_set_transaction_object();
     $primary_registration = $this->_transaction->primary_registration();
     $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL;
     $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
     $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso');
     $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
     $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso');
     $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
     $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso');
     $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
     $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
     $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
     if ($attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) {
         $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder', 'event_espresso'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     } else {
         $this->_template_args['send_payment_reminder_button'] = '';
     }
     $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
     $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, TRUE);
     if (EE_Registry::instance()->CFG->currency->sign_b4) {
         $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
     } else {
         $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
     }
     $this->_template_args['amount_due_class'] = '';
     if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
         // paid in full
         $this->_template_args['amount_due'] = FALSE;
     } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
         // overpaid
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') > 0) {
         // monies owing
         $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') == 0) {
         // no payments made yet
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') == 0) {
         // free event
         $this->_template_args['amount_due'] = FALSE;
     }
     $payment_method = $this->_transaction->payment_method();
     $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso');
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     // link back to overview
     $this->_template_args['txn_overview_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL;
     // next link
     $next_txn = $this->_transaction->next(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
     // previous link
     $previous_txn = $this->_transaction->previous(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
     // were we just redirected here after adding a new registration ???
     if (isset($this->_req_data['redirect_from'], $this->_req_data['EVT_ID'], $this->_req_data['event_name'])) {
         if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations', 'espresso_registrations_new_registration', $this->_req_data['EVT_ID'])) {
             $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
             $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations', 'action' => 'new_registration', 'return' => 'default', 'TXN_ID' => $this->_transaction->ID(), 'event_id' => $this->_req_data['EVT_ID']), REG_ADMIN_URL);
             $this->_admin_page_title .= '">';
             $this->_admin_page_title .= sprintf(__('Add Another New Registration to Event: "%1$s" ?'), htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8'));
             $this->_admin_page_title .= '</a>';
         }
         EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
     }
     // grab messages at the last second
     $this->_template_args['notices'] = EE_Error::get_notices();
     // path to template
     $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
     $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE);
     // the details template wrapper
     $this->display_admin_page_with_sidebar();
 }
 /**
  * @deprecated 4.9.0
  * @param  string $messenger_name    name of EE_messenger
  * @param  string $message_type_name name of EE_message_type
  * @return array
  */
 public function get_fields($messenger_name, $message_type_name)
 {
     // EE_messages has been deprecated
     $this->_class_is_deprecated(__FUNCTION__);
     EE_Registry::instance()->load_helper('MSG_Template');
     return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
 }
 public function newsletter_send_form_skeleton()
 {
     $list_table = $this->_list_table_object;
     $codes = array();
     //need to templates for the newsletter message type for the template selector.
     $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
     $mtps = EEM_Message_Template_Group::instance()->get_all(array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')));
     foreach ($mtps as $mtp) {
         $name = $mtp->name();
         $values[] = array('text' => empty($name) ? __('Global', 'event_espresso') : $name, 'id' => $mtp->ID());
     }
     //need to get a list of shortcodes that are available for the newsletter message type.
     $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', FALSE);
     foreach ($shortcodes as $field => $shortcode_array) {
         $codes[$field] = implode(', ', array_keys($shortcode_array));
     }
     $shortcodes = $codes;
     $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
     $form_template_args = array('form_action' => admin_url('admin.php?page=espresso_registrations'), 'form_route' => 'newsletter_selected_send', 'form_nonce_name' => 'newsletter_selected_send_nonce', 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), 'redirect_back_to' => $this->_req_action, 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), 'shortcodes' => $shortcodes, 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration');
     EEH_Template::display_template($form_template, $form_template_args);
 }
 /**
  * sets the _existing_admin_settings property can be overridden by child classes.  We do this so we only do database calls if needed.
  *
  * @access protected
  * @return void
  */
 protected function _set_existing_admin_settings($messenger = NULL)
 {
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     $active_message_types = !empty($messenger) ? $active_messengers[$messenger]['settings'][$messenger . '-message_types'] : array();
     $actives = $this->_messages_item_type == 'messenger' ? $active_messengers : $active_message_types;
     $this->_existing_admin_settings = isset($actives[$this->name]['settings']) ? $actives[$this->name]['settings'] : null;
 }
 /**
  * get_fields
  * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
  *
  * @param  string $messenger_name    name of EE_messenger
  * @param  string $message_type_name name of EE_message_type
  * @return array
  */
 public static function get_fields($messenger_name, $message_type_name)
 {
     $template_fields = array();
     /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
     $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
     $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
     $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
     if (!EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
         return array();
     }
     //okay now let's assemble an array with the messenger template fields added to the message_type contexts.
     foreach ($message_type->get_contexts() as $context => $details) {
         foreach ($messenger->get_template_fields() as $field => $value) {
             $template_fields[$context][$field] = $value;
         }
     }
     if (empty($template_fields)) {
         EE_Error::add_error(__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return array();
     }
     return $template_fields;
 }
 /**
  * this handles saving the settings for a messenger or message type
  * @return json success or fail message
  */
 public function save_settings()
 {
     if (!isset($this->_req_data['type'])) {
         EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         $this->_template_args['error'] = TRUE;
         $this->_return_json();
     }
     if ($this->_req_data['type'] == 'messenger') {
         $settings = $this->_req_data['messenger_settings'];
         //this should be an array.
         $messenger = $settings['messenger'];
         //let's setup the settings data
         foreach ($settings as $key => $value) {
             switch ($key) {
                 case 'messenger':
                     unset($settings['messenger']);
                     break;
                 case 'message_types':
                     if (isset($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'])) {
                         foreach ($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'] as $mt => $v) {
                             if (isset($settings['message_types'][$mt])) {
                                 $settings[$messenger . '-message_types'][$mt]['settings'] = isset($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt]) ? $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt] : array();
                             }
                         }
                     } else {
                         foreach ($value as $mt => $v) {
                             //let's see if this message type is already present and has settings.
                             $settings[$messenger . '-message_types'][$mt]['settings'] = array();
                         }
                     }
                     //k settings are set let's get rid of the message types index
                     unset($settings['message_types']);
                     break;
                 default:
                     $settings[$key] = $value;
                     break;
             }
         }
         $this->_active_messengers[$messenger]['settings'] = $settings;
     } else {
         if ($this->_req_data['type'] == 'message_type') {
             $settings = $this->_req_data['message_type_settings'];
             $messenger = $settings['messenger'];
             $message_type = $settings['message_type'];
             foreach ($settings as $key => $value) {
                 switch ($key) {
                     case 'messenger':
                         unset($settings['messenger']);
                         break;
                     case 'message_type':
                         unset($settings['message_type']);
                         break;
                     default:
                         $settings['settings'][$key] = $value;
                         unset($settings[$key]);
                         break;
                 }
             }
             $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type] = $settings;
         }
     }
     //okay we should have the data all setup.  Now we just update!
     $success = EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
     if ($success) {
         EE_Error::add_success(__('Settings updated', 'event_espresso'));
     } else {
         EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
     $this->_template_args['success'] = $success;
     $this->_return_json();
 }
 /**
  * This will return an array of shortcodes => labels from the messenger and message_type objects associated with this template.
  *
  * @since 4.3.0
  * @uses  EEH_MSG_Template::get_shortcodes()
  *
  * @param string $context what context we're going to return shortcodes for
  * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are to be returned.
  * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the unique shortcodes for all the given (or all) fields.
  * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no shortcodes found.
  */
 public function get_shortcodes($context, $fields = array(), $merged = FALSE)
 {
     $messenger = $this->messenger();
     $message_type = $this->message_type();
     EE_Registry::instance()->load_helper('MSG_Template');
     return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
 }
 /**
  * unsets the active if we can't find the file (failsafe)
  *
  * @access private
  * @param  string $active_name name of messenger or message type
  * @param  string $kind        messenger or message_type?
  * @return void
  */
 private function _unset_active($active_name, $kind)
 {
     //pluralize
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     EE_Registry::instance()->load_helper('MSG_Template');
     if ($kind == 'messenger') {
         unset($active_messengers[$active_name]);
         EEH_MSG_Template::update_to_inactive($active_name);
         if (isset($this->_active_messengers[$active_name])) {
             unset($this->_active_messengers[$active_name]);
         }
     } else {
         foreach ($active_messengers as $messenger => $settings) {
             if (!empty($settings['settings'][$messenger . '-message_types'][$active_name])) {
                 unset($active_messengers[$messenger]['settings'][$messenger . '-message_types'][$active_name]);
             }
         }
         EEH_MSG_Template::update_to_inactive('', $active_name);
         if (isset($this->_active_message_types[$active_name])) {
             unset($this->_active_message_types[$active_name]);
         }
     }
     EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
 }
    /**
     * 	column_actions
     * @param \EE_Transaction $item
     * @return string
     */
    function column_actions(EE_Transaction $item)
    {
        $registration = $item->primary_registration();
        $attendee = $registration->attendee();
        EE_Registry::instance()->load_helper('MSG_Template');
        //Build row actions
        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->ID()), TXN_ADMIN_URL);
        $dl_invoice_lnk_url = $registration->invoice_url();
        $dl_receipt_lnk_url = $registration->receipt_url();
        $view_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $registration->ID()), REG_ADMIN_URL);
        $send_pay_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $item->ID()), TXN_ADMIN_URL);
        //Build row actions
        $view_lnk = '
			<li>
				<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
					<span class="dashicons dashicons-cart"></span>
				</a>
			</li>';
        //only show invoice link if message type is active.
        if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('invoice')) {
            $dl_invoice_lnk = '
		<li>
			<a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text">
				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
			</a>
		</li>';
        } else {
            $dl_invoice_lnk = '';
        }
        //only show receipt link if message type is active.
        if ($attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('receipt')) {
            $dl_receipt_lnk = '
		<li>
			<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '" target="_blank" href="' . $dl_receipt_lnk_url . '" class="tiny-text">
				<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
			</a>
		</li>';
        } else {
            $dl_receipt_lnk = '';
        }
        //only show payment reminder link if the message type is active.
        if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
            $send_pay_lnk = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder') ? '
			<li>
				<a href="' . $send_pay_lnk_url . '" title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
					<span class="dashicons dashicons-email-alt"></span>
				</a>
			</li>' : '';
            $send_pay_lnk = $item->get('STS_ID') != EEM_Transaction::complete_status_code && $item->get('STS_ID') != EEM_Transaction::overpaid_status_code ? $send_pay_lnk : '';
        } else {
            $send_pay_lnk = '';
        }
        $view_reg_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $registration->ID()) ? '
			<li>
				<a href="' . $view_reg_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
					<span class="dashicons dashicons-clipboard"></span>
				</a>
			</li>' : '';
        return $this->_action_string($view_lnk . $dl_invoice_lnk . $dl_receipt_lnk . $view_reg_lnk . $send_pay_lnk, $item, 'ul', 'txn-overview-actions-ul');
    }
 /**
  * 	_transaction_details
  * generates HTML for the View Transaction Details Admin page
  *
  * @access protected
  *	@return void
  */
 protected function _transaction_details()
 {
     do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
     EE_Registry::instance()->load_helper('MSG_Template');
     $this->_set_transaction_status_array();
     $this->_template_args = array();
     $this->_template_args['transactions_page'] = $this->_wp_page_slug;
     $this->_set_transaction_object();
     $primary_registration = $this->_transaction->primary_registration();
     $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : NULL;
     $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
     $this->_template_args['txn_nmbr']['label'] = __('Transaction Number', 'event_espresso');
     $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_datetime('TXN_timestamp', 'l F j, Y', 'g:i:s a');
     $this->_template_args['txn_datetime']['label'] = __('Date', 'event_espresso');
     $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
     $this->_template_args['txn_status']['label'] = __('Transaction Status', 'event_espresso');
     $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
     $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
     $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid');
     if ($attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_transactions_send_payment_reminder')) {
         EE_Registry::instance()->load_helper('MSG_Template');
         $this->_template_args['send_payment_reminder_button'] = EEH_MSG_Template::is_mt_active('payment_reminder') && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code ? EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'send_payment_reminder', 'TXN_ID' => $this->_transaction->ID(), 'redirect_to' => 'view_transaction'), TXN_ADMIN_URL), __(' Send Payment Reminder'), 'button secondary-button right', 'dashicons dashicons-email-alt') : '';
     } else {
         $this->_template_args['send_payment_reminder_button'] = '';
     }
     $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
     $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, TRUE);
     if (EE_Registry::instance()->CFG->currency->sign_b4) {
         $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due'];
     } else {
         $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign;
     }
     $this->_template_args['amount_due_class'] = '';
     if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
         // paid in full
         $this->_template_args['amount_due'] = FALSE;
     } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
         // overpaid
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') > 0) {
         // monies owing
         $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') > 0 && $this->_transaction->get('TXN_paid') == 0) {
         // no payments made yet
         $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
     } elseif ($this->_transaction->get('TXN_total') == 0) {
         // free event
         $this->_template_args['amount_due'] = FALSE;
     }
     $payment_method = $this->_transaction->payment_method();
     $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() : __('Unknown', 'event_espresso');
     $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
     // link back to overview
     $this->_template_args['txn_overview_url'] = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : TXN_ADMIN_URL;
     //next and previous links
     $next_txn = $this->_transaction->next(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['next_transaction'] = $next_txn ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
     $previous_txn = $this->_transaction->previous(null, array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), 'TXN_ID');
     $this->_template_args['previous_transaction'] = $previous_txn ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), TXN_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
     // grab messages at the last second
     $this->_template_args['notices'] = EE_Error::get_notices();
     // path to template
     $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
     $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, $this->_template_args, TRUE);
     // the details template wrapper
     $this->display_admin_page_with_sidebar();
 }
 /**
  * _generate_new_templates
  * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
  * automatically create the defaults for the event.  The user would then be redirected to edit the default context
  * for the event.
  *
  *
  * @param  string $messenger     the messenger we are generating templates for
  * @param array   $message_types array of message types that the templates are generated for.
  * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to indicate
  *                               the message_template_group being used as the base.
  *
  * @param bool    $global
  * @return array|bool array of data required for the redirect to the correct edit page or bool if
  *                               encountering problems.
  * @throws \EE_Error
  */
 protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
 {
     //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.
     if (empty($message_types)) {
         return true;
     }
     return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
 }
 /**
  * This tests the generate_default_message_templates method with using the
  * FHEE__EE_messenger__get_default_message_types__default_types filter to add a
  * bogus message_type string.  No errors should be triggered, and the invalid default mt
  * should NOT be added to the active array for the messenger.
  *
  * @since 4.6
  * @group 7595
  */
 public function test_filtered_default_message_types_on_activation()
 {
     EE_Registry::instance()->load_helper('MSG_Template');
     EE_Registry::instance()->load_helper('Activation');
     //let's clear out all active messengers to get an accurate test of initial generation of message templates.
     global $wpdb;
     $mtpg_table = $wpdb->prefix . 'esp_message_template_group';
     $mtp_table = $wpdb->prefix . 'esp_message_template';
     $evt_mtp_table = $wpdb->prefix . 'esp_event_message_template';
     $query = "DELETE FROM  {$mtpg_table} WHERE 'GRP_ID' > 0";
     $wpdb->query($query);
     $query = "DELETE FROM {$mtp_table} WHERE 'MTP_ID' > 0";
     $wpdb->query($query);
     $query = "DELETE FROM {$evt_mtp_table} WHERE 'EMT_ID' > 0";
     $wpdb->query($query);
     EEH_MSG_Template::update_active_messengers_in_db(array());
     //set a filter for the invalid message type
     add_filter('FHEE__EE_messenger__get_default_message_types__default_types', function ($default_types, $messenger) {
         $default_types[] = 'bogus_message_type';
         return $default_types;
     }, 10, 2);
     //activate messages... if there's any problems then errors will trigger a fail.
     EEH_Activation::generate_default_message_templates();
     //all went well so let's make sure the activated system does NOT have our invalid message type string.
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     foreach ($active_messengers as $messenger => $settings) {
         $this->assertFalse(isset($settings['settings'][$messenger . '-message_types']['bogus_message_type']), sprintf('The %s messenger should not have "bogus_message_type" active on it but it does.', $messenger));
     }
 }
 protected function _registration_legend_items()
 {
     $fc_items = array('star-icon' => array('class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', 'desc' => __('This is the Primary Registrant', 'event_espresso')), 'view_details' => array('class' => 'dashicons dashicons-clipboard', 'desc' => __('View Registration Details', 'event_espresso')), 'edit_attendee' => array('class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', 'desc' => __('Edit Contact Details', 'event_espresso')), 'view_transaction' => array('class' => 'dashicons dashicons-cart', 'desc' => __('View Transaction Details', 'event_espresso')), 'view_invoice' => array('class' => 'dashicons dashicons-media-spreadsheet', 'desc' => __('View Transaction Invoice', 'event_espresso')));
     if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration')) {
         $fc_items['resend_registration'] = array('class' => 'dashicons dashicons-email-alt', 'desc' => __('Resend Registration Details', 'event_espresso'));
     } else {
         $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
     }
     if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
         $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
         if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
             $fc_items['view_related_messages'] = array('class' => $related_for_icon['css_class'], 'desc' => $related_for_icon['label']);
         }
     }
     $sc_items = array('approved_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')), 'pending_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')), 'incomplete_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, FALSE, 'sentence')), 'not_approved' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')), 'declined_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, FALSE, 'sentence')), 'cancelled_status' => array('class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, FALSE, 'sentence')));
     return array_merge($fc_items, $sc_items);
 }
 /**
  * This does some validation of incoming params gets the url trigger from the defined method in the specific child class and then filters the results.
  *
  * @param string          $context           The message type context
  * @param string          $sending_messenger The sending messenger
  * @param EE_Registration $registration      Registration object
  *
  * @return string          generated url
  */
 public function get_url_trigger($context, $sending_messenger, EE_Registration $registration)
 {
     //validate context
     //valid context?
     if (!isset($this->_contexts[$context])) {
         throw new EE_Error(sprintf(__('The context %s is not a valid context for %s.', 'event_espresso'), $context, get_class($this)));
     }
     //valid sending_messenger?
     $not_valid_msgr = FALSE;
     foreach ($this->_with_messengers as $generating => $sendings) {
         if (empty($sendings) || array_search($sending_messenger, $sendings) === FALSE) {
             $not_valid_msgr = TRUE;
         }
     }
     if ($not_valid_msgr) {
         throw new EE_Error(sprintf(__('The given sending messenger string (%s) does not match a valid sending messenger with the %s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.', 'event_espresso'), $sending_messenger, get_class($this)));
     }
     EE_Registry::instance()->load_helper('MSG_Template');
     return EEH_MSG_Template::generate_url_trigger($sending_messenger, $this->_active_messenger->name, $context, $this->name, $registration, $this->_GRP_ID, $this->_get_id_for_msg_url($context, $registration));
 }
    /**
     * column_actions
     *
     * @access public
     * @param \EE_Registration $item
     * @return string
     */
    function column_actions(EE_Registration $item)
    {
        EE_Registry::instance()->load_helper('MSG_Template');
        $attendee = $item->attendee();
        $ticket = $item->ticket();
        $this->_set_related_details($item);
        //Build row actions
        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL);
        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit_attendee', 'post' => $item->attendee_ID()), REG_ADMIN_URL);
        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
        //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'resend_registration', '_REG_ID' => $item->ID()), REG_ADMIN_URL, true);
        //Build row actions
        $view_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', 'espresso_registrations_view_registration', $item->ID()) ? '
			<li>
			<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-clipboard"></div>
			</a>
			</li>' : '';
        $edit_lnk = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', 'espresso_registrations_edit_attendee') && $attendee instanceof EE_Attendee ? '
			<li>
			<a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
			</a>
			</li>' : '';
        $resend_reg_lnk = $attendee instanceof EE_Attendee && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'espresso_registrations_resend_registration', $item->ID()) ? '
			<li>
			<a href="' . $resend_reg_lnk_url . '" title="' . esc_attr__('Resend Registration Details', 'event_espresso') . '" class="tiny-text">
				<div class="dashicons dashicons-email-alt"></div>
			</a>
			</li>' : '';
        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $this->_transaction_details['id']), TXN_ADMIN_URL);
        $view_txn_lnk = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? '
			<li>
			<a class="ee-status-color-' . $this->_transaction_details['status'] . '" href="' . $view_txn_lnk_url . '"  title="' . $this->_transaction_details['title_attr'] . '" class="tiny-text">
				<div class="dashicons dashicons-cart"></div>
			</a>
			</li>' : '';
        //invoice link
        $dl_invoice_lnk_url = $item->invoice_url();
        //only show invoice link if message type is active.
        if ($item->is_primary_registrant() && $attendee instanceof EE_Attendee && EEH_MSG_Template::is_mt_active('invoice')) {
            $dl_invoice_lnk = '
		<li>
			<a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '" target="_blank" href="' . $dl_invoice_lnk_url . '" class="tiny-text">
				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
			</a>
		</li>';
        } else {
            $dl_invoice_lnk = '';
        }
        return $this->_action_string($view_lnk . $edit_lnk . $resend_reg_lnk . $view_txn_lnk . $dl_invoice_lnk, $item, 'ul', 'reg-overview-actions-ul');
    }
 /**
  * This simply validates active messengers and message types to ensure they actually match installed messengers and message types.  If there's a mismatch then we deactivate the messenger/message type and ensure all related db rows are set inactive.
  *
  * @since 4.3.1
  *
  * @return void
  */
 public static function validate_messages_system()
 {
     //include our helper
     EE_Registry::instance()->load_helper('MSG_Template');
     //get active and installed  messengers/message types.
     $active_messengers = EEH_MSG_Template::get_active_messengers_in_db();
     $installed = EEH_MSG_Template::get_installed_message_objects();
     $installed_messengers = $installed_mts = array();
     //set up the arrays so they can be handled easier.
     foreach ($installed['messengers'] as $im) {
         if ($im instanceof EE_messenger) {
             $installed_messengers[$im->name] = $im;
         }
     }
     foreach ($installed['message_types'] as $imt) {
         if ($imt instanceof EE_message_type) {
             $installed_mts[$imt->name] = $imt;
         }
     }
     //now let's loop through the active array and validate
     foreach ($active_messengers as $messenger => $active_details) {
         //first let's see if this messenger is installed.
         if (!isset($installed_messengers[$messenger])) {
             //not set so let's just remove from actives and make sure templates are inactive.
             unset($active_messengers[$messenger]);
             EEH_MSG_Template::update_to_inactive($messenger);
             continue;
         }
         //messenger is active, so let's just make sure that any active message types not installed are deactivated.
         $mts = !empty($active_details['settings'][$messenger . '-message_types']) ? $active_details['settings'][$messenger . '-message_types'] : array();
         foreach ($mts as $mt_name => $mt) {
             if (!isset($installed_mts[$mt_name])) {
                 unset($active_messengers[$messenger]['settings'][$messenger . '-message_types'][$mt_name]);
                 EEH_MSG_Template::update_to_inactive($messenger, $mt_name);
             }
         }
     }
     //all done! let's update the active_messengers.
     EEH_MSG_Template::update_active_messengers_in_db($active_messengers);
     do_action('AHEE__EEH_Activation__validate_messages_system');
     return;
 }
 /**
  * Activates the specified messenger.
  *
  * @param string $messenger_name
  * @param array  $message_type_names        An array of message type names to activate with this messenger.
  *                                          If included we do NOT setup the default message types
  *                                          (assuming they are already setup.)
  * @param bool   $update_active_messengers_option
  *
  * @return array of generated templates
  * @throws \EE_Error
  */
 public function activate_messenger($messenger_name, $message_type_names = array(), $update_active_messengers_option = true)
 {
     $templates = array();
     // grab the messenger to work with.
     $messenger = $this->messenger_collection()->get_by_info($messenger_name);
     // it's inactive. Activate it.
     if ($messenger instanceof EE_messenger) {
         $this->_active_messengers[$messenger->name] = $messenger;
         //activate incoming message types set to be activated with messenger.
         $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
         // setup any initial settings for the messenger if necessary.
         $this->add_settings_for_messenger($messenger->name);
         if ($update_active_messengers_option) {
             $this->update_active_messengers_option();
             $this->update_has_activated_messengers_option();
         }
         //generate new templates if necessary and ensure all related templates that are already in the database are
         //marked active.  Note, this will also deactivate a message type for a messenger if the template
         //cannot be successfully created during its attempt (only happens for global template attempts).
         if (!empty($message_type_names)) {
             $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
             EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
         }
     }
     return $templates;
 }