.*?<\/div>)/i',"
\\1",$text,1);
$text = preg_replace ('/(
)/i',"\\1",$text);
$text = preg_replace ('/(<\/lang_..>)/i',"\\1",$text);
$text = ''.$text.'';
return str_replace("","",str_replace("","",lang_picker($text)) );
}
function safe_link(){
global $post;
$idpost = $post;
$permalink = get_settings('home') . '/' . get_settings('blogfilename') . '?p=' . $idpost->ID;
if ($idpost->post_status == 'static')
$permalink .= '&static=1';
return $permalink;
}
//--------------------------
function lp_other_langs($none='none', $before='', $pre='(', $post=')'){
global $page, $pages, $lp_lang_pref, $default_lang, $lang_rewrite;
$content = $pages[$page-1].get_the_title();//fred
$link = safe_link();
$before = lang_picker($before);
$after = lang_picker($after);
$pre = lang_picker($pre);
$post = lang_picker($post);
$other_langs = lang_picker($none);
if (preg_match_all ( '//', $content , $match, PREG_PATTERN_ORDER)) {
$match = array_unique($match[1]);
$other_langs = $before;
if ($lp_lang_pref != $default_lang && !in_array($default_lang, $match)) {
if ('' != get_settings('permalink_structure') && $lang_rewrite) {
$other_langs .= "$pre".get_trans($default_lang)."$post";//fred
} else {
$other_langs .= "$pre".get_trans($default_lang)."$post";
}
}
foreach ($match as $lang){
if ($lp_lang_pref != $lang) {
if ('' != get_settings('permalink_structure') && $lang_rewrite) {
$other_langs .= "$pre".get_trans($lang)."$post";//fred
} else {
$other_langs .= "$pre".get_trans($lang)."$post";//fred ?-> &
}
}
}
if($other_langs != $before)//fred to avoid empty
$other_langs .= $after;
else
$other_langs = $none;
}
echo $other_langs;
}
function lp($todo='',$return=0){
global $lp_running;
if ($todo=='start' OR (!$todo && !$lp_running)){
ob_start("lang_picker");
$lp_running=TRUE;
} else if ($todo=='stop' OR (!$todo && $lp_running)) {
$lp_running=FALSE;
ob_end_flush();
} else if ($todo && $return) {
return lang_picker($todo);
} else if ($todo) {
echo lang_picker($todo);
}
}
//------------fred-------------------
function get_users_pref_lang(){
GLOBAL $default_lang,$knownlangs;
$deflang = $default_lang;
# An advanced PHP Language Detection Script
# by Fibergeek (fibergeek @ codegurus.be)
#
# This script is a modification to a script I found via google
#
# 2003-12-18 - Version 1 (I added...)
# - you can now also specify the country code in the $knowlangs array
# - extraction of the country code ($country)
# - I fully documented the code
#
# 2004-01-07 - Version 2 (I added...)
# - you can now make $knowlangs NULL (the script will set to array to all known languages (ISO-639))
#
# NOTE : for those using Brion's script, I renamed $lastquality to $quality
#
# Found at URL : http://mail.wikipedia.org/pipermail/wikitech-l/2002-October/001068.html
# Assumed creator : Brion VIBBER (wikitech-l@wikipedia.org)
# HTTP reference : RFC 2616 - ftp://ftp.isi.edu/in-notes/rfc2616.txt
# ==================================================================================================
# TODO
# You need to add the 2 lines to your source code, and change the content of them of course ;-)
# ==================================================================================================
#$knownlangs = NULL; // default to all known languages (ISO-639)
#$deflang = NULL; // there is no default language
#
#$knownlangs = array('en-us', 'en-uk', 'en', 'nl'); // We know : English (US & UK) and Dutch
#$deflang = 'en-uk'; // In case of an error, we default to English UK
# ==================================================================================================
# INFORMATION
# The following variables are returned by this program
# $lclist : the full list with the languages accepted by the client's browser
# $lctag : the tag we are supporting (includes the country code if any)
# $quality : the quality
# $lang : the language code
# $country : the country code (if any)
#
# The following variables are used by this program (and may be overwritten if you use them also!)
# $langtag
# $qvalue
# $eachbit
# $tmppos
# $tmplclist
# $tmplctag
# $tmptagarray
# ==================================================================================================
# ==================================================================================================
# THE SCRIPT
# ==================================================================================================
# Check that $knowlangs is an array!
# NOTE : the list is taken from this URL : http://www.w3.org/WAI/ER/IG/ert/iso639.htm
if(!is_array($knownlangs))
{
if(is_string($knownlangs) || is_object($knownlangs) || $knownlangs != NULL)
die("Fibergeek's PHP Language Detection Script : You need define \$knownlangs as an array or as NULL!
\n");
$knownlangs = array('aa', 'ab', 'af', 'am', 'ar', 'as', 'ay', 'az', 'ba', 'be', 'bg', 'bh', 'bi', 'bn', 'bo', 'br', 'ca', 'co', 'cs', 'cy', 'da', 'de', 'dz', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'fi', 'fj', 'fo', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'ha', 'hi', 'hr', 'hu', 'hy', 'ia', 'ie', 'ik', 'in', 'is', 'it', 'iw', 'ja', 'ji', 'jw', 'ka', 'kk', 'kl', 'km', 'kn', 'ko', 'ks', 'ku', 'ky', 'la', 'ln', 'lo', 'lt', 'lv', 'mg', 'mi', 'mk', 'ml', 'mn', 'mo', 'mr', 'ms', 'mt', 'my', 'na', 'ne', 'nl', 'no', 'oc', 'om', 'or', 'pa', 'pl', 'ps', 'pt', 'qu', 'rm', 'rn', 'ro', 'ru', 'rw', 'sa', 'sd', 'sg', 'sh', 'si', 'sk', 'sl', 'sm', 'sn', 'so', 'sq', 'sr', 'ss', 'st', 'su', 'sv', 'sw', 'ta', 'te', 'tg', 'th', 'ti', 'tk', 'tl', 'tn', 'to', 'tr', 'ts', 'tt', 'tw', 'uk', 'ur', 'uz', 'vi', 'vo', 'wo', 'xh', 'yo', 'zh', 'zu');
}
# Initalisation of the default variables
if(isset($HTTP_SERVER_VARS))
$lclist = trim($HTTP_SERVER_VARS['HTTP_ACCEPT_LANGUAGE']); # PHP running from a server
else
$lclist = trim($_SERVER['HTTP_ACCEPT_LANGUAGE']); # PHP 5.0 when the old server variables disabled
$lctag = $deflang;
$tmppos = strpos($lctag, '-');
$quality = 0.0;
if($tmppos == FALSE or $tmppos == NULL)
{
$lang = $deflang;
if($deflang == NULL)
$country = NULL;
else
$country = '';
}
else
{
$lang = substr($lctag, 0, $tmppos);
$country = substr($lctag, $tmppos + 1);
echo "lang sub = $lang";
}
#
$langtag = '((?:[a-zA-Z]{1,8})(?:-[a-zA-Z]{1,8})*)';
$qvalue ='(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3}))';
$eachbit = '^' . $langtag . '(?:;q=' . $qvalue . ')?(?:,\s*)?(.*)$';
#
$tmplclist = $lclist;
# The loop
while(strlen($tmplclist))
{
if(preg_match("/$eachbit/", $tmplclist, $tmptagarray)) # requires 3.0.9
{
# Extract data from the tag list
$tmplctag = $tmptagarray[1];
$tmpquality = $tmptagarray[2];
if(strlen($tmpquality) == 0)
$tmpquality = 1;
$tmplclist = $tmptagarray[3];
# Find the tag in our $knownlangs array (this search includes the country code if set)
if(in_array($tmplctag, $knownlangs) and $tmpquality > $quality)
{
# Extract the language & quality
$lctag = $tmplctag;
$lang = $tmplctag;
$country = '';
$quality = $tmpquality;
}
else
{
# Not found, does the tag include a country code?
$tmppos = strpos($tmplctag, '-');
if($tmppos <> FALSE)
{
# OK, the tag includes a country code but it's not in the $knownlangs array, let's extract the language and look it up
if(in_array(substr($tmplctag, 0, $tmppos), $knownlangs) and $tmpquality > $quality)
{
# Extract the language, country & quality
$lctag = $tmplctag;
$lang = substr($tmplctag, 0, $tmppos);
$country = substr($tmplctag, $tmppos + 1);
$quality = $tmpquality;
}
}
}
}
else
{
# There was an error, abort the loop
break;
}
}
return $lang;
}//get_users_pref_lang()
?>