Theme router.plugin

From FUDforum Wiki
Revision as of 10:26, 19 January 2011 by Naudefj (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Theme_router.plugin is a plugin that can switch users from FUDforum's default theme to a custom theme based on language, operating system or browser type. For example, mobile phone users can be routed to a lo-fi theme, or French users can be routed to a French language theme.

Prerequisites

Setup the target themes in the Theme Manager before activating this plugin. When done, edit the plugin with a text editor to set the appropriate conditions and themes.

Code

An example theme_router.plugin file (used on the fudforum.org site):

<?php
// initialize plugin
plugin_add_hook('INITUSER', 'plugin_theme_router');

// override default theme
function plugin_theme_router($usr) {
	$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
	// $agent = $_SERVER['HTTP_USER_AGENT'];
 
	// Make language selection.
	if ($lang == 'af') {
		@define('fud_theme', 'theme/default_afrikaans/');
	} else if ($lang == 'ar') {
		@define('fud_theme', 'theme/default_arabic/');
	} else if ($lang == 'be-tarask') {
		@define('fud_theme', 'theme/default_belarusian/');
	} else if ($lang == 'br') {
		@define('fud_theme', 'theme/default_breton/');
	} else if ($lang == 'bg') {
		@define('fud_theme', 'theme/default_bulgarian/');
	} else if ($lang == 'ca') {
		@define('fud_theme', 'theme/default_catalan/');
	} else if ($lang == 'cs') {
		@define('fud_theme', 'theme/default_czech/');
	} else if ($lang == 'da') {
		@define('fud_theme', 'theme/default_danish/');
	} else if ($lang == 'de') {
		@define('fud_theme', 'theme/default_german/');
	} else if ($lang == 'el') {
		@define('fud_theme', 'theme/default_greek/');
	} else if ($lang == 'eo') {
		@define('fud_theme', 'theme/default_esperanto/');
	} else if ($lang == 'es') {
		@define('fud_theme', 'theme/default_spanish/');
	} else if ($lang == 'fi') {
		@define('fud_theme', 'theme/default_finnish/');
	} else if ($lang == 'fr') {
		@define('fud_theme', 'theme/default_french/');
	} else if ($lang == 'gl') {
		@define('fud_theme', 'theme/default_galician/');
	} else if ($lang == 'gsw') {
		@define('fud_theme', 'theme/default_swiss_german/');
	} else if ($lang == 'hsb') {
		@define('fud_theme', 'theme/default_upper_sorbian/');
	} else if ($lang == 'hu') {
		@define('fud_theme', 'theme/default_hungarian/');
	} else if ($lang == 'ia') {
		@define('fud_theme', 'theme/default_interlingua/');
	} else if ($lang == 'id') {
		@define('fud_theme', 'theme/default_indonesian/');
	} else if ($lang == 'it') {
		@define('fud_theme', 'theme/default_italian/');
	} else if ($lang == 'ja') {
		@define('fud_theme', 'theme/default_japanese/');
	} else if ($lang == 'ko') {
		@define('fud_theme', 'theme/default_korean/');
	} else if ($lang == 'lb') {
		@define('fud_theme', 'theme/default_luxembourgish/');
	} else if ($lang == 'lt') {
		@define('fud_theme', 'theme/default_lithuanian/');
	} else if ($lang == 'lv') {
		@define('fud_theme', 'theme/default_latvian/');
	} else if ($lang == 'mk') {
		@define('fud_theme', 'theme/default_macedonian/');
	} else if ($lang == 'nl') {
		@define('fud_theme', 'theme/default_dutch/');
	} else if ($lang == 'no') {
		@define('fud_theme', 'theme/default_norwegian/');
	} else if ($lang == 'oc') {
		@define('fud_theme', 'theme/default_occitan/');
	} else if ($lang == 'pl') {
		@define('fud_theme', 'theme/default_polish/');
	} else if ($lang == 'pt') {
		@define('fud_theme', 'theme/default_portuguese/');
	} else if ($lang == 'pt-br') {
		@define('fud_theme', 'theme/default_portuguese_br/');
	} else if ($lang == 'ps') {
		@define('fud_theme', 'theme/default_pashto/');
	} else if ($lang == 'ro') {
		@define('fud_theme', 'theme/default_romanian/');
	} else if ($lang == 'ru') {
		@define('fud_theme', 'theme/default_russian/');
	} else if ($lang == 'sk') {
		@define('fud_theme', 'theme/default_slovak/');
	} else if ($lang == 'sr') {
		@define('fud_theme', 'theme/default_serbian_cyrillic/');
	} else if ($lang == 'sv') {
		@define('fud_theme', 'theme/default_swedish/');
	} else if ($lang == 'tr') {
		@define('fud_theme', 'theme/default_turkish/');
	} else if ($lang == 'ug-arab') {
		@define('fud_theme', 'theme/default_uyghur/');
	} else if ($lang == 'uk') {
		@define('fud_theme', 'theme/default_ukrainian/');
	} else if ($lang == 'vi') {
		@define('fud_theme', 'theme/default_vietnamese/');
	} else if ($lang == 'zh-hans') {
		@define('fud_theme', 'theme/default_chinese/');
	}

	// Lo-fi theme for mobile phones.
	// if (stripos($agent, 'iPhone') || stripos($agent, 'android')) {
	//    @define('fud_theme', 'theme/lo-fi/');
	// }
}
Languages
Personal tools