Commit f28b40e2 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Rewrite forum post email links to go through mnet host (bug 3012)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 2e7df01a
......@@ -965,6 +965,27 @@ class PluginAuthXmlrpc extends PluginAuth {
return $values;
}
public static function get_jump_link($hostwwwroot, $hostapp, $href) {
$jumpurl = $hostwwwroot . '/';
$jumpurl .= $hostapp == 'moodle' ? 'auth/mnet/jump.php' : 'auth/xmlrpc/jump.php';
// Remove trailing slash on wwwroot
$jumpurl .= '?hostwwwroot=' . substr(get_config('wwwroot'), 0, -1) . '&wantsurl=';
$localpart='';
$urlparts = parse_url($href);
if ($urlparts) {
if (isset($urlparts['path'])) {
$localpart .= $urlparts['path'];
}
if (isset($urlparts['query'])) {
$localpart .= '?'.$urlparts['query'];
}
if (isset($urlparts['fragment'])) {
$localpart .= '#'.$urlparts['fragment'];
}
}
$href = $jumpurl . urlencode($localpart);
return $href;
}
}
?>
......@@ -445,7 +445,6 @@ class InteractionForumInstance extends InteractionInstance {
}
class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
protected $postid;
......@@ -501,7 +500,9 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
$posttime = strftime(get_string('strftimedaydatetime'), $post->ctime);
$htmlbody = $post->body;
$textbody = trim(html2text($post->body));
$postlink = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid . '#post' . $this->postid;
$postlink = 'interaction/forum/topic.php?id=' . $post->topicid . '#post' . $this->postid;
$localpostlink = get_config('wwwroot') . $postlink;
foreach ($this->users as &$user) {
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
......@@ -516,12 +517,23 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
$unsubscribeid = $post->{$type . 'id'};
$unsubscribelink = get_config('wwwroot') . 'interaction/forum/unsubscribe.php?' . $type . '=' . $unsubscribeid . '&key=' . $subscribers[$user->id]->key;
if ($user->mnethostwwwroot) {
if (!isset($mnetpostlink)) {
require_once(get_config('docroot') . 'auth/xmlrpc/lib.php');
}
$userpostlink = $mnetpostlink = PluginAuthXmlrpc::get_jump_link($user->mnethostwwwroot, $user->mnethostapp, $postlink);
}
else {
$userpostlink = $localpostlink;
}
$user->message = get_string_from_language($lang, 'forumposttemplate', 'interaction.forum',
$post->subject ? $post->subject : get_string_from_language($lang, 're', 'interaction.forum', $post->topicsubject),
display_name($post->poster, $user),
$posttime,
$textbody,
$postlink,
$userpostlink,
$type,
$unsubscribelink
);
......@@ -530,7 +542,7 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
display_name($post->poster, $user),
$posttime,
$htmlbody,
$postlink, $postlink,
$userpostlink, $userpostlink,
$type,
$unsubscribelink, $unsubscribelink
);
......
......@@ -96,7 +96,7 @@ function activity_get_users($activitytype, $userids=null, $userobjs=null, $admin
$sql = '
SELECT
u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
p.method, ap.value AS lang
p.method, ap.value AS lang, aic.value AS mnethostwwwroot, h.appname AS mnethostapp
FROM {usr} u
LEFT JOIN {usr_activity_preference} p
ON (p.usr = u.id AND p.activity = ?)' . (empty($admininstitutions) ? '' : '
......@@ -105,6 +105,12 @@ function activity_get_users($activitytype, $userids=null, $userobjs=null, $admin
AND ui.institution IN ('.join(',',array_map('db_quote',$admininstitutions)).'))') . '
LEFT OUTER JOIN {usr_account_preference} ap
ON (ap.usr = u.id AND ap.field = \'lang\')
LEFT OUTER JOIN {auth_instance} ai
ON (ai.id = u.authinstance AND ai.authname = \'xmlrpc\')
LEFT OUTER JOIN {auth_instance_config} aic
ON (aic.instance = ai.id AND aic.field = \'wwwroot\')
LEFT OUTER JOIN {host} h
ON aic.value = h.wwwroot
WHERE TRUE';
if (!empty($userobjs) && is_array($userobjs)) {
$sql .= ' AND u.id IN (' . implode(',',db_array_to_ph($userobjs)) . ')';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment