language = LANGUAGE; //plaats pad in een global pathobj in de vorm pathobj[0] = array('id' => 12, 'code' => 'home', 'handler' => 'home.php') $pathobj = array(); //wanneer er alleen een taal is en geen pad bekend naar pagina, neem dan default if (count($patharray) == 0) $patharray[] = getHomeCodeForLanguage(); //bepaal het pad naar de pagina $pid = 0; //eerste naam in pad heeft altijd parent 0 $pathremain = array(); //gedeelte wat na de laatst gevonden handler komt for ($i = 0; $i < count($patharray); $i++) { $po = getPathObjectForCodeAndParent($pid, $patharray[$i]); if ($po) { $pathobj[] = $po; $pid = $po['id']; } else { //kennelijk is er een onderdeel van het pad niet gevonden //voeg deze toe aan de pathremain array $pathremain[] = $patharray[$i]; } } if (count($pathobj) > 0) { $po = $pathobj[count($pathobj) - 1]; define('PAGEID', $po['id']); define('PAGETITLE', $po['title']); define('PAGECODE', $po['code']); define('PAGEHANDLER', $po['handler']); $html->title = $po['title']; include_once('handlers/'.$po['handler']); } else { //pad bestaat niet, toon 404 pagina header("HTTP/1.0 404 Not Found"); } /************************************************************************/ function getAcceptLanguage() { global $languages; $langs = array(); if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // break up string into pieces (languages and q factors) preg_match_all('/([a-z]{2}(-[a-z]{2})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); if (count($lang_parse[1])) { $langs = array_combine($lang_parse[1], $lang_parse[4]); // create a list like "en" => 0.8 // set default to 1 for any without q factor foreach ($langs as $lang => $val) { if ($val === '') $langs[$lang] = 1; } arsort($langs, SORT_NUMERIC);// sort list based on value // look through sorted list and use first one that matches our languages foreach ($langs as $lang => $val) { if (in_array($lang, $languages)) { return $lang; } } } } return DEFAULTLANGUAGE;//default } /***********************************************************************/ function getHomeCodeForLanguage() { global $db; $sql = sprintf('SELECT code FROM structure WHERE parent = 0 AND position = 0 AND language = %s LIMIT 1', $db->esc(LANGUAGE)); if ($result = $db->query($sql)) { if ($row = $result->fetch_row()) return $row[0]; } return false; } /************************************************************************/ function getPathObjectForCodeAndParent($parent, $code) { global $db; $sql = sprintf("SELECT id, code, handler, title FROM structure WHERE code=%s AND language=%s AND parent = %u AND visible = 1 LIMIT 1", $db->esc($code), $db->esc(LANGUAGE), $parent); if ($result = $db->query($sql)) { if ($row = $result->fetch_assoc()) { return $row; //return hele associatieve array } } return false; } ?>