diff --git a/helper.php b/helper.php index cf4203b..a854b22 100644 --- a/helper.php +++ b/helper.php @@ -704,7 +704,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { } break; default: - $page = $this->_apply_macro($page); + $page = $this->_apply_macro($page, $parent_id); resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID if (auth_quickaclcheck($page) >= AUTH_READ) $pages[] = $page; @@ -793,11 +793,44 @@ function _get_included_pages_from_meta_instructions($instructions) { } return $pages; } - + + /** + * Get wiki language from "HTTP_ACCEPT_LANGUAGE" + * We allow the pattern e.g. "ja,en-US;q=0.7,en;q=0.3" + */ + function _get_language_of_wiki($id, $parent_id) { + global $conf; + $result = $conf['lang']; + if(strpos($id, '@BROWSER_LANG@') !== false){ + $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/"; + if(preg_match_all( + $brlangp, $_SERVER["HTTP_ACCEPT_LANGUAGE"], + $matches, PREG_SET_ORDER + )){ + $langs = array(); + foreach($matches as $match){ + $langname = $match[1] == '*' ? $conf['lang'] : $match[1]; + $qvalue = $match[4] == '' ? 1.0 : $match[4]; + $langs[$langname] = $qvalue; + } + arsort($langs); + foreach($langs as $lang => $langq){ + $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); + resolve_pageid(getNS($parent_id), $testpage, $exists); + if($exists){ + $result = $lang; + break; + } + } + } + } + return cleanID($result); + } + /** * Makes user or date dependent includes possible */ - function _apply_macro($id) { + function _apply_macro($id, $parent_id) { global $INFO; global $auth; @@ -847,6 +880,7 @@ function _apply_macro($id) { '@USER@' => cleanID($user), '@NAME@' => cleanID($INFO['userinfo']['name']), '@GROUP@' => cleanID($group), + '@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id), '@YEAR@' => date('Y',$time_stamp), '@MONTH@' => date('m',$time_stamp), '@WEEK@' => date('W',$time_stamp),