/**
  * load_message_types
  * globs the supplied filepath and adds any found
  *
  * @param  string $folder
  * @throws \EE_Error
  */
 public function load_message_types_from_folder($folder = '')
 {
     //make sure autoloaders are set (fail-safe)
     EED_Messages::set_autoloaders();
     $folder = !empty($folder) ? $folder : EE_LIBRARIES . 'messages' . DS . 'message_type';
     $folder .= $folder[strlen($folder) - 1] != DS ? DS : '';
     // get all the files in that folder that end in ".class.php
     $filepaths = apply_filters('FHEE__EE_messages__get_installed__messagetype_files', glob($folder . '*.class.php'));
     if (empty($filepaths)) {
         return;
     }
     foreach ((array) $filepaths as $file_path) {
         // extract filename from path
         $file_path = basename($file_path);
         // now remove any file extensions
         $message_type_class_name = substr($file_path, 0, strpos($file_path, '.'));
         //if this class name doesn't represent a message type class, then we just skip.
         if (strpos(strtolower($message_type_class_name), 'message_type') === false) {
             continue;
         }
         if (!class_exists($message_type_class_name)) {
             throw new EE_Error(sprintf(__('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), $message_type_class_name, $file_path));
         }
         $this->_load_message_type(new $message_type_class_name());
     }
 }
 /**
  * Resets the registry.
  *
  * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
  * is used in a multisite install.  Here is a list of things that are NOT reset.
  *
  * - $_dependency_map
  * - $_class_abbreviations
  * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
  * - $REQ:  Still on the same request so no need to change.
  * - $CAP: There is no site specific state in the EE_Capability class.
  * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
  *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
  * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
  *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
  *             switch or on the restore.
  * - $modules
  * - $shortcodes
  * - $widgets
  *
  * @param boolean $hard whether to reset data in the database too, or just refresh
  * the Registry to its state at the beginning of the request
  * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too,
  * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
  * currently reinstantiate the singletons at the moment)
  * @param   bool    $reset_models    Defaults to true.  When false, then the models are not reset.  This is so client
  *                                  code instead can just change the model context to a different blog id if necessary
  *
  * @return EE_Registry
  */
 public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
 {
     $instance = self::instance();
     EEH_Activation::reset();
     //properties that get reset
     $instance->_cache_on = true;
     $instance->CFG = EE_Config::reset($hard, $reinstantiate);
     $instance->CART = null;
     $instance->MRM = null;
     $instance->LIB = new stdClass();
     //messages reset
     EED_Messages::reset();
     if ($reset_models) {
         foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
             $instance->reset_model($model_name);
         }
     }
     return $instance;
 }
 /**
  * 	resend_reg_confirmation_email
  */
 public static function resend_reg_confirmation_email()
 {
     EE_Registry::instance()->load_core('Request_Handler');
     $reg_url_link = EE_Registry::instance()->REQ->get('token');
     // was a REG_ID passed ?
     if ($reg_url_link) {
         $registration = EE_Registry::instance()->load_model('Registration')->get_one(array(array('REG_url_link' => $reg_url_link)));
         if ($registration instanceof EE_Registration) {
             // resend email
             EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
         } else {
             EE_Error::add_error(__('The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         }
     } else {
         EE_Error::add_error(__('The Registration Confirmation email could not be sent because a registration token is missing or invalid.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
     // request sent via AJAX ?
     if (EE_FRONT_AJAX) {
         echo json_encode(EE_Error::get_notices(FALSE));
         die;
         // or was JS disabled ?
     } else {
         // save errors so that they get picked up on the next request
         EE_Error::get_notices(TRUE, TRUE);
         wp_safe_redirect(add_query_arg(array('e_reg_url_link' => $reg_url_link), EE_Registry::instance()->CFG->core->thank_you_page_url()));
     }
 }
 /**
  * load the active files needed (key word... NEEDED)
  * @param string $kind indicates what kind of files we are loading.
  * @param array $actives indicates what active types of the $kind are actually to be loaded.
  */
 private function _load_files($kind, $actives)
 {
     $active_names = array();
     $base_path = EE_LIBRARIES . 'messages' . DS . $kind . DS;
     if (empty($actives)) {
         return false;
     }
     //make sure autoloaders are set (failsafe)
     EED_Messages::set_autoloaders();
     //make sure $actives is an array
     $actives = (array) $actives;
     EE_Registry::instance()->load_helper('File');
     foreach ($actives as $active) {
         $msg_name = 'EE_' . ucwords(str_replace(' ', '_', $active)) . '_' . $kind;
         $filename = $msg_name . '.class.php';
         $load_file = $base_path . DS . $filename;
         if (is_readable($load_file)) {
             require_once $load_file;
             $active_names[$active] = $msg_name;
         } else {
             $this->_unset_active($active, $kind);
             //set WP_Error
             return EE_Error::add_error(sprintf(__("Missing messages system file set as inactive: (%s) %s has been made inactive.", 'event_espresso'), $load_file, $msg_name), __FILE__, __FUNCTION__, __LINE__);
         }
     }
     return $active_names;
 }
 /**
  * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data array.
  * @return bool success/fail
  */
 protected function _process_resend_registration()
 {
     $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
     do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
     return $this->_template_args['success'];
 }
 /**
  * load_messengers
  * globs the supplied filepath and adds any found
  *
  * @return array
  */
 public function load_active_messengers_from_db()
 {
     //make sure autoloaders are set (fail-safe)
     EED_Messages::set_autoloaders();
     $active_messengers = apply_filters('FHEE__EEH_MSG_Template__get_active_messengers_in_db', get_option('ee_active_messengers', array()));
     foreach ((array) $active_messengers as $active_messenger_classname => $active_messenger) {
         $this->_load_messenger($active_messenger);
     }
 }
 /**
  * metabox content for all template pack and variation selection.
  *
  * @since 4.5.0
  *
  * @return string
  */
 public function template_pack_meta_box()
 {
     $this->_set_message_template_group();
     //setup template pack select values.
     $template_packs = EED_Messages::get_template_packs();
     $tp_select_values = array();
     foreach ($template_packs as $tp) {
         //only include template packs that support this messenger and message type!
         $supports = $tp->get_supports();
         if (!isset($supports[$this->_message_template_group->messenger()]) || !in_array($this->_message_template_group->message_type(), $supports[$this->_message_template_group->messenger()])) {
             //not supported
             continue;
         }
         $tp_select_values[] = array('text' => $tp->label, 'id' => $tp->dbref);
     }
     //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.
     if (empty($tp_select_values)) {
         $tp_select_values[] = array('text' => __('Default', 'event_espresso'), 'id' => 'default');
     }
     //setup variation select values for the currently selected template.
     $variations = $this->_message_template_group->get_template_pack()->get_variations($this->_message_template_group->messenger(), $this->_message_template_group->message_type());
     $variations_select_values = array();
     foreach ($variations as $variation => $label) {
         $variations_select_values[] = array('text' => $label, 'id' => $variation);
     }
     $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
     $template_args['template_packs_selector'] = EEH_Form_Fields::select_input('MTP_template_pack', $tp_select_values, $this->_message_template_group->get_template_pack_name());
     $template_args['variations_selector'] = EEH_Form_Fields::select_input('MTP_template_variation', $variations_select_values, $this->_message_template_group->get_template_pack_variation());
     $template_args['template_pack_label'] = $template_pack_labels->template_pack;
     $template_args['template_variation_label'] = $template_pack_labels->template_variation;
     $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
     $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
     $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
     EEH_Template::display_template($template, $template_args);
 }
 /**
  *  Resets all the static properties in this class when called.
  */
 public static function reset()
 {
     self::$_EEMSG = null;
     self::$_message_resource_manager = null;
     self::$_MSG_PROCESSOR = null;
     self::$_MSG_PATHS = null;
     self::$_TMP_PACKS = array();
 }
 /**
  * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data array.
  * @return bool success/fail
  */
 protected function _process_resend_registration()
 {
     add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
     $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
     do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
     return $this->_template_args['success'];
 }
 /**
  *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
  *
  *  @since 4.9.0
  */
 protected function _send_now()
 {
     $msg_ids = $this->_get_msg_ids_from_request();
     EED_Messages::send_now($msg_ids);
     $this->_redirect_after_action(false, '', '', array(), true);
 }
 /**
  * @deprecated 4.5.0
  */
 public function send_newsletter_message($contacts, $grp_id)
 {
     self::doing_it_wrong_call(__METHOD__);
     EED_Messages::send_newsletter_message($contacts, $grp_id);
 }
 /**
  * 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 retreived.
  *
  * @since 4.5.0
  *
  * @return EE_Messages_Template_Pack
  */
 public function get_template_pack()
 {
     $pack_name = $this->get_template_pack_name();
     return EED_Messages::get_template_pack($pack_name);
 }
 /**
  * @since      4.5.0
  * @deprecated 4.9.0   Moved to EED_Messages Module
  * @param string   $messenger    a string matching a valid active messenger in the system
  * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still required to send along the message type to the messenger because this is used for determining what specific variations might be loaded for the generated message.
  * @param stdClass $message      a stdClass object in the format expected by the messenger.
  *
  * @return bool          success or fail.
  */
 public function send_message_with_messenger_only($messenger, $message_type, $message)
 {
     // EE_messages has been deprecated
     $this->_class_is_deprecated(__FUNCTION__);
     //setup for sending to new method.
     /** @type EE_Messages_Queue $queue */
     $queue = EE_Registry::instance()->load_lib('Messages_Queue');
     //make sure we have a proper message object
     if (!$message instanceof EE_Message && is_object($message) && isset($message->content)) {
         $msg = EE_Message_Factory::create(array('MSG_messenger' => $messenger, 'MSG_message_type' => $message_type, 'MSG_content' => $message->content, 'MSG_subject' => $message->subject));
     } else {
         $msg = $message;
     }
     if (!$msg instanceof EE_Message) {
         return false;
     }
     //make sure any content in a content property (if not empty) is set on the MSG_content.
     if (!empty($msg->content)) {
         $msg->set('MSG_content', $msg->content);
     }
     $queue->add($msg);
     return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
 }
 /**
  * Takes care of loading the Messages system controller into the $_EEMSG property
  *
  * @since 4.5.0
  *
  * @return void
  */
 protected static function _load_controller()
 {
     if (!self::$_EEMSG instanceof EE_messages) {
         self::set_autoloaders();
         self::$_EEMSG = new EE_messages();
     }
 }
 private static function _set_autoloader()
 {
     EED_Messages::set_autoloaders();
 }
 protected function _set_list_table_views_default()
 {
     //for notification related bulk actions we need to make sure only active messengers have an option.
     EED_Messages::set_autoloaders();
     $EEMSG = EE_Registry::instance()->load_lib('messages');
     $active_mts = $EEMSG->get_active_message_types();
     //key= bulk_action_slug, value= message type.
     $match_array = array('approve_registration' => 'registration', 'decline_registration' => 'declined_registration', 'pending_registration' => 'pending_approval', 'no_approve_registration' => 'not_approved_registration', 'cancel_registration' => 'cancelled_registration');
     /** setup reg status bulk actions **/
     $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
     if (in_array($match_array['approve_registration'], $active_mts) && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')) {
         $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', 'event_espresso');
     }
     $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
     if (in_array($match_array['decline_registration'], $active_mts) && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')) {
         $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', 'event_espresso');
     }
     $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
     if (in_array($match_array['pending_registration'], $active_mts) && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')) {
         $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify', 'event_espresso');
     }
     $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
     if (in_array($match_array['no_approve_registration'], $active_mts) && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')) {
         $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify', 'event_espresso');
     }
     $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
     if (in_array($match_array['cancel_registration'], $active_mts) && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')) {
         $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify', 'event_espresso');
     }
     $this->_views = array('all' => array('slug' => 'all', 'label' => __('View All Registrations', 'event_espresso'), 'count' => 0, 'bulk_action' => array_merge($def_reg_status_actions, array('trash_registrations' => __('Trash Registrations', 'event_espresso')))), 'month' => array('slug' => 'month', 'label' => __('This Month', 'event_espresso'), 'count' => 0, 'bulk_action' => array_merge($def_reg_status_actions, array('trash_registrations' => __('Trash Registrations', 'event_espresso')))), 'today' => array('slug' => 'today', 'label' => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))), 'count' => 0, 'bulk_action' => array_merge($def_reg_status_actions, array('trash_registrations' => __('Trash Registrations', 'event_espresso')))));
     if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', 'espresso_registrations_delete_registration')) {
         $this->_views['incomplete'] = array('slug' => 'incomplete', 'label' => __('Incomplete', 'event_espresso'), 'count' => 0, 'bulk_action' => array('trash_registrations' => __('Trash Registrations', 'event_espresso')));
         $this->_views['trash'] = array('slug' => 'trash', 'label' => __('Trash', 'event_espresso'), 'count' => 0, 'bulk_action' => array('restore_registrations' => __('Restore Registrations', 'event_espresso'), 'delete_registrations' => __('Delete Registrations Permanently', 'event_espresso')));
     }
 }
 /**
  * This is used to execute an immediate call to the run_cron task performed by EED_Messages
  * @param string $task The task the request is being generated for.
  */
 public static function initiate_immediate_request_on_cron($task)
 {
     $request_args = EE_Messages_Scheduler::get_request_params($task);
     //set those request args in the request so it gets picked up
     foreach ($request_args as $request_key => $request_value) {
         EE_Registry::instance()->REQ->set($request_key, $request_value);
     }
     EED_Messages::instance()->run_cron();
 }