Domain Empire

PhpBB SEO Virtual Folder Links Fix

Spaceship Spaceship
Watch

BillyConnite

<img src="images/smilies/biggrin.gif" border="0" cVIP Member
Impact
109
Hey all,

For those of you who use phpBB and the common seo mod (phpbb-seo.com), you may have noticed that many links in non-prosilver and non-subsilver templates are broken due to the virtual topic folders.

This mod will save you editing your template files to correct those broken links.

You'll find this particularly useful if you have multiple styles running off the same forum, or have a styles demo forum running. Given i have 130 styles added to my forum host, editing the styles 1 by 1 was simply not an option.

Here's a fix i just coded up, it's easy to do and only takes a few minutes.

WARNING: This has been tested in a phpBB root install(/), and sub-folder(/subfolder/) install only, NOT a sub-subfolder (/subfolder/subfolder/) install. Good luck!

OPEN:
Code:
includes/template.php
FIND:
Code:
	function assign_vars($vararray)
	{
ADD AFTER:
Code:
	// get config
	global $config;
FIND:
Code:
		foreach ($vararray as $key => $val)
		{
ADD AFTER:
Code:
		// START: MOD by http://forums.do/
		$linkNames=array('S_LOGIN_ACTION','S_LOGIN_ACTION','S_SEARCHBOX_ACTION'); // Names of uncommon links
			if(substr($key,0,2)=='U_'||in_array($key,$linkNames)) // Check if this is a link
			{
				if(substr($val,0,7)!='http://'&&substr($val,0,3)!='../') // Make sure the link isn't already good
				{
				$instFolderName=$config['script_path']; // Get the install path of phpBB
				// The following is to remove slashes carefully, incase phpBB is installed in a consecutive sub-folder
					if(substr($instFolderName,0,1)=='/')
					{
					$instFolderName=substr($instFolderName,1); // Remove the first slash, if there is one
					}
					if(substr($instFolderName,-1,1)=='/')
					{
					$instFolderName=substr($instFolderName,0,-1); // Remove the last slash, if there is one
					}
				$allowedFolders=array('adm','ucp',$instFolderName); // Define allowed folder; admin panel, user control panel, install folder
				$strURIx=explode("/",$_SERVER['REQUEST_URI']); // Split up the URI to find the first folder
					if(!in_array($strURIx[count($strURIx)-2],$allowedFolders)&&count($strURIx)>2) // Check to see we are in a folder that is not normal
					{
						if(substr($val,0,2)=='./') // Some links begin with ./ and some with just /
						{
						$val='.'.$val; // Adda period to go up one level.
						}
					}
				}
			}
		// END: MOD by http://forums.do/
FIND:
Code:
	function assign_var($varname, $varval)
	{
ADD AFTER:
Code:
	// get config
	global $config;
	// START: MOD by http://forums.do/
	$linkNames=array('S_LOGIN_ACTION','S_LOGIN_ACTION','S_SEARCHBOX_ACTION'); // Names of uncommon links
		if(substr($varname,0,2)=='U_'||in_array($varname,$linkNames)) // Check if this is a link
		{
			if(substr($varval,0,7)!='http://'&&substr($varval,0,3)!='../') // Make sure the link isn't already good
			{
			$instFolderName=$config['script_path']; // Get the install path of phpBB
			// The following is to remove slashes carefully, incase phpBB is installed in a consecutive sub-folder
				if(substr($instFolderName,0,1)=='/')
				{
				$instFolderName=substr($instFolderName,1); // Remove the first slash, if there is one
				}
				if(substr($instFolderName,-1,1)=='/')
				{
				$instFolderName=substr($instFolderName,0,-1); // Remove the last slash, if there is one
				}
			$allowedFolders=array('adm','ucp',$instFolderName); // Define allowed folder; admin panel, user control panel, install folder
			$strURIx=explode("/",$_SERVER['REQUEST_URI']); // Split up the URI to find the first folder
				if(!in_array($strURIx[count($strURIx)-2],$allowedFolders)&&count($strURIx)>2) // Check to see we are in a folder that is not normal
				{
					if(substr($varval,0,2)=='./') // Some links begin with ./ and some with just /
					{
					$varval='.'.$varval; // Adda period to go up one level.
					}
				}
			}
		}
	// END: MOD by http://forums.do/

I'll update this as i find any glitches.

Enjoy!

-Rhett
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back