diff --git a/message/lib.php b/message/lib.php index eae88ae4be1..7ad36cf9fe7 100644 --- a/message/lib.php +++ b/message/lib.php @@ -2308,6 +2308,34 @@ function get_message_processors($ready = false) { return $processors; } +/** + * Get an instance of the message_output class for one of the output plugins. + * @param string $type the message output type. E.g. 'email' or 'jabber'. + * @return message_output message_output the requested class. + */ +function get_message_processor($type) { + global $CFG; + + // Note, we cannot use the get_message_processors function here, becaues this + // code is called during install after installing each messaging plugin, and + // get_message_processors caches the list of installed plugins. + + $processorfile = $CFG->dirroot . "/message/output/{$type}/message_output_{$type}.php"; + if (!is_readable($processorfile)) { + throw new coding_exception('Unknown message processor type ' . $type); + } + + include_once($processorfile); + + $processclass = 'message_output_' . $type; + if (!class_exists($processclass)) { + throw new coding_exception('Message processor ' . $type . + ' does not define the right class'); + } + + return new $processclass(); +} + /** * Get messaging outputs default (site) preferences * @@ -2345,11 +2373,8 @@ function translate_message_default_setting($plugindefault, $processorname) { ); // define the default setting - if ($processorname == 'email') { - $default = MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF; - } else { - $default = MESSAGE_PERMITTED; - } + $processor = get_message_processor($processorname); + $default = $processor->get_default_messaging_settings(); // Validate the value. It should not exceed the maximum size if (!is_int($plugindefault) || ($plugindefault > 0x0f)) { diff --git a/message/output/email/message_output_email.php b/message/output/email/message_output_email.php index 7f27f62614d..5e56f1b4b05 100644 --- a/message/output/email/message_output_email.php +++ b/message/output/email/message_output_email.php @@ -88,6 +88,15 @@ class message_output_email extends message_output { } } + /** + * @return int the Default message output settings for this output, for + * message providers that do not specify what the settings should be for + * this output in the messages.php file. + */ + public function get_default_messaging_settings() { + return MESSAGE_PERMITTED + MESSAGE_DEFAULT_LOGGEDIN + MESSAGE_DEFAULT_LOGGEDOFF; + } + /** * Loads the config data from database to put on the form (initial load) * @param array $preferences preferences array diff --git a/message/output/lib.php b/message/output/lib.php index f669c50d0f5..7d7aa3a6c08 100644 --- a/message/output/lib.php +++ b/message/output/lib.php @@ -55,6 +55,14 @@ abstract class message_output { return true; } + /** + * @return int the Default message output settings for this output, for + * message providers that do not specify what the settings should be for + * this output in the messages.php file. + */ + public function get_default_messaging_settings() { + return MESSAGE_PERMITTED; + } }