moderation.php breaking Google SEO redirects
#1
Google SEO partly supports virtual directory structure for urls. Even if no problem is presented using the Combined Styles scheme, the core moderation system gets partly broken.

The reason being the following piece of code within moderation.php:
function moderation_redirect($url, $message="", $title="")
{
 global $mybb;
 if(!empty($mybb->input['url']))
 {
 $url = htmlentities($mybb->input['url']);
 }

 if(my_strpos($url, $mybb->settings['bburl'].'/') !== 0)
 {
 if(my_strpos($url, '/') === 0)
 {
 $url = my_substr($url, 1);
 }
 $url_segments = explode('/', $url);
 $url = $mybb->settings['bburl'].'/'.end($url_segments);
 }

 redirect($url, $message, $title);
}
https://github.com/mybb/mybb/blob/feature/moderation.php#L3528

For whatever reasoning there might be, MyBB breaks the URL in line#3542.

This might not be a bug within MyBB itself but in Google SEO (which doesn't fully supports this feature). However, I lack the ability to benefit behind this code.
Reply
#2
I think this function should be deprecated by using redirect().

I suppose the main reason for it is for the search feature. However, even so there is stuff that makes no sense.
https://github.com/mybb/mybb/blob/dd9606....php#L3282

$return_url = htmlspecialchars_uni($mybb->get_input('url'));
moderation_redirect($return_url, $lang->redirect_customtool_search);

//...

function moderation_redirect($url, $message="", $title="")
{
	global $mybb;
	if(!empty($mybb->input['url']))
	{
		$url = htmlentities($mybb->input['url']);
	}
Reply
#3
Thanks for pointing this out Omar.
Here's my quick fix for building the redirect link in moderation.php with the Google SEO plugin enabled, along with custom url_forum / url_thread settings.

I'm using 'topic' for threads, and 'forum' for the forum sections. These two segments will most likely need changing to match your own forum.
In future I'd like to query the Google SEO settings directly to automatically get/set those vars to avoid hardcoding them.

google_seo_url_forums  - Forum URL scheme  - forum/{url}
google_seo_url_threads - Thread URL scheme - topic/{url}

/**
 * Special redirect that takes a return URL into account
 *
 * Added fix for Google SEO plugin issues :
 * moderation.php breaking Google SEO redirects
 * https://community.mybb.com/thread-226655.html
 *
 * @param string $url URL
 * @param string $message Message
 * @param string $title Title
 */
function moderation_redirect( $url, $message = '', $title = '' )
{
	global $mybb;

	if( ! empty( $mybb->input['url'] ) ) {
		$url = htmlentities( $mybb->input['url'] );
	}

	if( my_strpos( $url, $mybb->settings['bburl'] . '/' ) !== 0 )
	{
		if( my_strpos( $url, '/' ) === 0 ) {
			$url = my_substr( $url, 1 );
		}

		$url_segments   = explode( '/', $url );
		$thread_segment = 'topic'; // TODO :: get setting directly from seo plugin
        $forum_segment  = 'forum'; // TODO :: get setting directly from seo plugin

		if( ! empty( $url_segments[0] ) && ( $url_segments[0] === $thread_segment || $url_segments[0] === $forum_segment ) ) {
            $url = $mybb->settings['bburl'] . '/' . implode( '/', $url_segments );
        } else {
            $url = $mybb->settings['bburl'] . '/' . end( $url_segments );
        }
	}

	redirect( $url, $message, $title );
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)