$value){ if(is_array($value)){ printValues($value); } else{ if ((strpos($key, 'numFound') !== false)) { $values[] = $value; $numFound = $value; } elseif ((strpos($key, 'id') !== false)) { $values[] = $value; $redirect = $value; } $count++; } } // Return total count and values found in array return array('total' => $count, 'values' => $values,'numFound' => $numFound, 'redirectUrl' => $redirect); } function solQuery($lang,$docPath) { $documentUrl="https://documents.westerndigital.com".$docPath; $url = 'http://10.252.23.151:8983/solr/western-digital-'.$lang.'/select?fl=id&sourceType:documents.westerndigital.com&q=id:'.$documentUrl.'&hl=off&spellcheck=off&wt=json'; #echo $url ."
"; $contents = file_get_contents($url); if($contents !== false){ //Print out the contents. #echo $contents; $solr = json_decode($contents,true); $result = printValues($solr); #echo "

" . $result["total"] . " value(s) found:

"; #echo implode "numFound" . $result["numFound"] . "
"; #echo implode "redirect" . $result["redirectUrl"] . "
"; #echo implode("
", $result["values"]); return array('numFound' => $result["numFound"], 'redirectUrl' => $result["redirectUrl"]); } else { return array('numFound' => 0, 'redirectUrl' => ""); } } function redirectPage($loc) { header("Location: ".$loc, true, 301); exit(); } function errorPage($loc) { header("Location: ".$loc, true, 404); exit(); } if ( (isset($_GET['docPath']) && isset($_GET['lang'])) && count($_GET) > 1 ) { $docPath= htmlspecialchars($_GET["docPath"]); $lang= $_GET["lang"]; #echo $lang; #echo $url; if ((strpos($lang, 'en-us') !== false)) { $rsp=solQuery($lang,$docPath); if ($rsp["numFound"] > 0) { #echo "redirect". $rsp["redirectUrl"] . "
"; redirectPage($rsp["redirectUrl"]); } else { echo "Page not found :".$docPath."
"; } } else { $tempLang=str_replace("-","_",$lang); if(strcmp($tempLang, 'cs_cz') == 0) { $tempLang="cz_cz"; } elseif (strcmp($tempLang, 'ar_sa') == 0) { $tempLang="ar_ae"; } elseif (strcmp($tempLang, 'es_la') == 0) { $tempLang="es_mx"; } $docPathChild=str_replace("en_us",$tempLang,$docPath); $rspChild=solQuery($lang,$docPathChild); if ($rspChild["numFound"] > 0) { #echo "redirect Child". $rspChild["redirectUrl"] . "
"; redirectPage($rspChild["redirectUrl"]); } else { $rsp1=solQuery($lang,$docPath); if ($rsp1["numFound"] > 0) { #echo "redirect". $rsp["redirectUrl"] . "
"; redirectPage($rsp1["redirectUrl"]); } else { echo "Page not found :".$docPath."
"; } } } } ?>