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

Add clean URL "User subdomain" option (bug #1006634)

This generates profile urls as subdomains of the site wwwroot.  For
example, http://bob.example.com rather than the default clean profile
URL http://example.com/user/bob

This option will not work without the appropriate rewrite rules,
documented at

https://wiki.mahara.org/index.php/System_Administrator%27s_Guide/Clean_URL_Configuration

Change-Id: I9e1cb479abf3b9535bd15efca7382f8352d6d893
parent 352c9373
......@@ -305,3 +305,8 @@ $cfg->cleanurlvalidate = '/^[a-z0-9-]*$/';
// Setting this to false will remove the "Change profile URL" option from the settings page.
$cfg->cleanurlusereditable = true;
// The following option will generate subdomain-style profile urls like http://bob.mahara.example.com
// Warning: Enabling this option on your site is likely to cause users with open sessions to be logged out on all profile pages.
// See https://wiki.mahara.org/index.php/System_Administrator%27s_Guide/Clean_URL_Configuration#User_Subdomains
// $cfg->cleanurlusersubdomains = true;
......@@ -1494,6 +1494,12 @@ function profile_url($user, $full=true, $useid=false) {
}
if ($wantclean && !is_null($urlid)) {
// If the host part of the url is not being returned, the user subdomain
// can't be added here, so ignore the subdomain setting when !$full.
if ($full && get_config('cleanurlusersubdomains')) {
list($proto, $rest) = explode('://', get_config('wwwroot'));
return $proto . '://' . $urlid . '.' . substr($rest, 0, -1);
}
$url = get_config('cleanurluserdefault') . '/' . $urlid;
}
else if (!empty($id)) {
......
......@@ -3469,6 +3469,10 @@ class View {
$institutions = get_records_assoc('institution', '', '', '', 'name,displayname');
$institutions['mahara']->displayname = get_config('sitename');
}
$wwwroot = get_config('wwwroot');
$needsubdomain = get_config('cleanurlusersubdomains');
foreach ($viewdata as &$v) {
if ($v->owner) {
$v->sharedby = View::owner_name($v->ownerformat, $owners[$v->owner]);
......@@ -3487,7 +3491,7 @@ class View {
$view->set('dirty', false);
$v['displaytitle'] = $view->display_title_editing();
$v['url'] = $view->get_url(false);
$v['fullurl'] = get_config('wwwroot') . $v['url'];
$v['fullurl'] = $needsubdomain ? $view->get_url(true) : ($wwwroot . $v['url']);
}
}
}
......
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