/** * 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 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)); }
/** * This does some validation of incoming params, determines what type of url is being prepped and returns the * appropriate url trigger * * @param EE_message_type $message_type * @param EE_Message $message * @param EE_Registration | null $registration The registration object must be included if this * is going to be a registration trigger url. * @param string $sending_messenger The (optional) sending messenger for the url. * * @return string * @throws EE_Error */ public static function get_url_trigger(EE_message_type $message_type, EE_Message $message, $registration = null, $sending_messenger = '') { //first determine if the url can be to the EE_Message object. if (!$message_type->always_generate()) { return EEH_MSG_Template::generate_browser_trigger($message); } //if $registration object is not valid then exit early because there's nothing that can be generated. if (!$registration instanceof EE_Registration) { throw new EE_Error(__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')); } //validate given context $contexts = $message_type->get_contexts(); if ($message->context() !== '' && !isset($contexts[$message->context()])) { throw new EE_Error(sprintf(__('The context %s is not a valid context for %s.', 'event_espresso'), $message->context(), get_class($message_type))); } //valid sending messenger but only if sending messenger set. Otherwise generating messenger is used. if (!empty($sending_messenger)) { $with_messengers = $message_type->with_messengers(); if (!isset($with_messengers[$message->messenger()]) || !in_array($sending_messenger, $with_messengers[$message->messenger()])) { throw new EE_Error(sprintf(__('The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$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($message_type))); } } else { $sending_messenger = $message->messenger(); } return EEH_MSG_Template::generate_url_trigger($sending_messenger, $message->messenger(), $message->context(), $message->message_type(), $registration, $message->GRP_ID()); }