MyBB Community Forums

Full Version: Pirvate Message - Unread notice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok I've found a bug in here.
While testing MyDownloads (a plugin I am making) (which is not in the root of MyBB but under /mydownloads folder), I've found that the link to the private message and to the user who has sent me the private message, links to /mydownloads/private.php and /mydownloads/member.php..etc

In global.lang.php
Find:
$l['newpm_notice_one'] = "<strong>You have one unread private message</strong> from <a href=\"{1}\">{2}</a> titled <a href=\"private.php?action=read&amp;pmid={3}\" style=\"font-weight: bold;\">{4}</a>";

Replace with:
$l['newpm_notice_one'] = "<strong>You have one unread private message</strong> from <a href=\"{1}\">{2}</a> titled <a href=\"{5}/private.php?action=read&amp;pmid={3}\" style=\"font-weight: bold;\">{4}</a>";

In global.php find:
$privatemessage_text = $lang->sprintf($lang->newpm_notice_one, get_profile_link($pm['fromuid']), htmlspecialchars_uni($pm['fromusername']), $pm['pmid'], htmlspecialchars_uni($pm['subject']));

Replace with:
$privatemessage_text = $lang->sprintf($lang->newpm_notice_one, get_profile_link($pm['fromuid']), htmlspecialchars_uni($pm['fromusername']), $pm['pmid'], htmlspecialchars_uni($pm['subject']), $mybb->settings['bburl']);

And in functions.php (we could fix it by editing init.php too)
/**
 * Get the profile link.
 *
 * @param int The user id of the profile.
 * @return string The url to the profile.
 */
function get_profile_link($uid=0)
{
	$link = str_replace("{uid}", $uid, PROFILE_URL);
	return htmlspecialchars_uni($link);
}

Should be:
/**
 * Get the profile link.
 *
 * @param int The user id of the profile.
 * @return string The url to the profile.
 */
function get_profile_link($uid=0)
{
	global $mybb;
	$link = str_replace("{uid}", $uid, $mybb->settings['bburl'].'/'.PROFILE_URL);
	return htmlspecialchars_uni($link);
}

There might exist a better fix but this one works.
MyBB uses relative links just about everywhere. As MyBB by default does not use any kind of directory structure (apart from the admin cp or archive, which is treated separately), this isn't a bug strictly speaking.

If you want to switch from relative URLs to absolute URLs everywhere, quite a lot of MyBB code would have to be changed. For example your get_profile_link() change may cause breakage elsewhere since callers of get_profile_link() currently don't expect to get a full URL back. So they may prepend bburl by themselves and end up with a broken link.

One workaround would be to use a <base> tag in your subdirectory (although this does not necessarily fix all of the issues), or not make any subdirectory at all.
Oh okay thank you
I've had this trouble working with MyTracker. The best thing (I found) was to create my own set of get_*_link/url functions. Especially the profile one!