Thread: Forum Display Enhancements - vB Enterprise Translator
View Single Post
  #181  
Old 08-17-2009, 05:44 PM
T2x T2x is offline
 
Join Date: May 2006
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey guys, I decided to do some work and make this mod comply with vBSEO's link consensus idea.

What this will do is change all of the translation likes like so:

For example if a page.html is translated into danish, the url will normally be:

www.website.com/page.html?language=da

This will change the format to

www.website.com/da/page.html

This is much better for SEO so I am sure all of you with vBSEO will like this.

WARNING: this will only work properly if your forum is installed at the BASE of your domain, so something like www.website.com/index.php, if your forums are installed at www.website.com/forums/index.php some parts of my code will not work properly for you!!

All you need to do is open up your vbseo.php and add this code right BELOW error_reporting(0);

Make sure it is ABOVE the includes

Code:
if(isset($_GET['vbseourl']))
{
	$processuri = 0;
	if(preg_match('/^..(\/|$)/',$_GET['vbseourl']))
	{
		$processuri = 1;
		$_GET['language'] = substr($_GET['vbseourl'],0,2);
		$_GET['vbseourl'] = substr($_GET['vbseourl'],3);
	}
	else if(preg_match('/^\/..(\/|$)/',$_GET['vbseourl']))
	{
		$processuri = 1;
		$_GET['language'] = substr($_GET['vbseourl'],1,2);
		$_GET['vbseourl'] = substr($_GET['vbseourl'],3);
	}
	else if(substr($_GET['vbseourl'],0,5) == "zh-CN" || substr($_GET['vbseourl'],0,5) == "zh-TW")
	{
		$processuri = 1;
		$_GET['language'] = substr($_GET['vbseourl'],0,5);
		$_GET['vbseourl'] = substr($_GET['vbseourl'],6);
	}
	else if(substr($_GET['vbseourl'],1,5) == "zh-CN" || substr($_GET['vbseourl'],1,5) == "zh-TW")
	{
		$processuri = 1;
		$_GET['language'] = substr($_GET['vbseourl'],1,5);
		$_GET['vbseourl'] = substr($_GET['vbseourl'],6);
	}

	if($processuri == 1)
	{
		if(substr($_SERVER['REQUEST_URI'],0,2)=='//')
			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],1);
		$tempuri = isset($_SERVER['HTTP_X_REWRITE_URL']) ? $_SERVER['HTTP_X_REWRITE_URL'] :
		(isset($_SERVER['HTTP_X_ORIGINAL_URL']) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
		(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] :
		(isset($_ENV['REQUEST_URI']) ? $_ENV['REQUEST_URI'] : $_SERVER['SCRIPT_NAME']))
		);
		if (strstr($tempuri, 'vbseo.php') && $_GET['vbseourl'])
			$tempuri = preg_replace('#vbseo\.php.*#', $_GET['vbseourl'] . ($_SERVER['QUERY_STRING']?'?'.$_SERVER['QUERY_STRING']:''), $tempuri);
		$tempuri = preg_replace('#\#.*$#', '', $tempuri);
		$_SERVER['REQUEST_URI'] = $tempuri;
		if(preg_match('/^\/..(\/|$)/',$_SERVER['REQUEST_URI']))
			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],3);
		else if(substr($_SERVER['REQUEST_URI'],1,5) == "zh-CN" || substr($_SERVER['REQUEST_URI'],1,5) == "zh-TW")
			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],6);
		$_SERVER['HTTP_X_REWRITE_URL'] = $_SERVER['REQUEST_URI'];
	}
}
else
{
	$processuri = 0;
	if(substr($_SERVER['REQUEST_URI'],0,2)=='//')
		$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],1);
	$tempuri = isset($_SERVER['HTTP_X_REWRITE_URL']) ? $_SERVER['HTTP_X_REWRITE_URL'] :
	(isset($_SERVER['HTTP_X_ORIGINAL_URL']) ? $_SERVER['HTTP_X_ORIGINAL_URL'] :
	(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] :
	(isset($_ENV['REQUEST_URI']) ? $_ENV['REQUEST_URI'] : $_SERVER['SCRIPT_NAME']))
	);
	$tempuri = preg_replace('#\#.*$#', '', $tempuri);

	if(preg_match('/^..(\/|$)/',$tempuri))
	{
		$processuri = 1;
		$_GET['language'] = substr($tempuri,0,2);
	}
	else if(preg_match('/^\/..(\/|$)/',$tempuri))
	{
		$processuri = 1;
		$_GET['language'] = substr($tempuri,1,2);
	}
	else if(substr($tempuri,0,5) == "zh-CN" || substr($tempuri,0,5) == "zh-TW")
	{
		$processuri = 1;
		$_GET['language'] = substr($tempuri,0,5);
	}
	else if(substr($tempuri,1,5) == "zh-CN" || substr($tempuri,1,5) == "zh-TW")
	{
		$processuri = 1;
		$_GET['language'] = substr($tempuri,1,5);
	}

	if($processuri == 1)
	{
		$_SERVER['REQUEST_URI'] = $tempuri;
		if(preg_match('/^\/..(\/|$)/',$_SERVER['REQUEST_URI']))
			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],3);
		else if(substr($_SERVER['REQUEST_URI'],1,5) == "zh-CN" || substr($_SERVER['REQUEST_URI'],1,5) == "zh-TW")
			$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'],6);
		$_SERVER['HTTP_X_REWRITE_URL'] = $_SERVER['REQUEST_URI'];
	}
}

If you want to 301 all of your old pages to the new link format, you can put this in your .htaccess above all of your existing rules

Code:
RewriteCond %{QUERY_STRING} (hl=|language=)(zh-TW|zh-CN|..)
RewriteRule ^(.*)$ http://%{HTTP_HOST}/%2/$1? [L,R=301]
Please note that this code assumes you are running vBSEO.

This code will fix translation for the base of your website if you want the following format. www.website.com/de or www.website.com/de/ . this only applies to your main page.

Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?((zh-CN|zh-TW|..))/?$ vbseo.php?vbseourl=$1/index.php [L,QSA]
If you want to generate proper sitemaps with all of your new language urls, all you need to do is open up your vbseo_sitemap_functions.php in your vbseo_sitemap directory then:

find this code

Code:
}else
    		    	$freq = $vboptions['vbseo_sm_freq_t'];
    		    	     
            	vbseo_log_entry("[showthread] forum_id: $forumid, thread_id: $threadrow[threadid], total posts: $totalposts, pages: $totalpages, views: $threadrow[views] $prior");

    			for($p=1; $p<=$totalpages; $p++)
    			{
Add this code right after it:

Code:
$alanguages = array('ar', 'bg', 'zh-CN', 'zh-TW', 'hr', 'cs', 'da', 'nl', 'fi', 'fr', 'de', 'el', 'iw', 'hu', 'it', 'ja', 'ko', 'no', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'es', 'sv', 'th', 'tr');
					if(!$archived)
					foreach($alanguages as $hl) {
					$vbseo_stat['t']++; 
					$currentthreadurl = vbseo_url_thread($threadrow, $p, $archived);
					$strlenhost = strlen($vbseo_vars['bburl']."/");
					vbseo_add_url(substr($currentthreadurl,0,$strlenhost).$hl."/".substr($currentthreadurl,$strlenhost), 0.3, $threadrow['lastpost'], $freq);
					}
make sure its before:

Code:
$vbseo_stat[$archived?'at':'t'] += vbseo_add_2urls(
    				vbseo_url_thread($threadrow, $p, $archived),
    				vbseo_url_thread($threadrow, $p, $archived, true),
    				$prior,
    				$threadrow['lastpost'],
					$freq
    			);
				
				}

    			if($showpost)
    			{

            	$getposts = $db->query("
If you notice there is an array in the code that looks like this
Code:
$alanguages = array('ar', 'bg', 'zh-CN', 'zh-TW', 'hr', 'cs', 'da', 'nl', 'fi', 'fr', 'de', 'el', 'iw', 'hu', 'it', 'ja', 'ko', 'no', 'pl', 'pt', 'ro', 'ru', 'sr', 'sk', 'es', 'sv', 'th', 'tr');
You should put the code of every language that you want added to your sitemap file in this array. Mine may differ from the languages you support so make sure you check it against your installation.


Just a note of caution: My fixes assume you are running a standard installation of apache with vBSEO. They may not work properly on some systems due to differences in the way that vBSEO handles some server variables. I recommend that you back up any files before editting them that way if you encounter problems you can restore your old versions.

I will be working on this code more so if any of you have issues please let me know and I will work on them.

If NLP-er would like he can provide a modified version of his flags in order to work with the new format or I will write up the code later today. This is necessary so that the flags show the proper links.

Anyway enjoy guys
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02111 seconds
  • Memory Usage 1,803KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete