<?php function rewrite_urlencode($str) { return str_replace('-','--',urlencode($str)); } function dblhyp($str) { return str_replace('-','--',$str); } function rewrite_build_query($parameters,$priorkeys=array('cmd')) { $parts=array(); foreach ($priorkeys as $k) { if ($parameters[$k]) if (is_array($parameters[$k])) { foreach ($parameters[$k] as $key=>$value) array_push($parts,urlencode($k).'['.urlencode($key).']-'.rewrite_urlencode($value)); } else array_push($parts,urlencode($k).'-'.rewrite_urlencode($parameters[$k])); } foreach ($parameters as $k=>$v) if ($v && !in_array($k,$priorkeys)) if (is_array($v)) { foreach ($v as $key=>$value) array_push($parts,urlencode($k).'['.urlencode($key).']-'.rewrite_urlencode($value)); } else array_push($parts,urlencode($k).'-'.rewrite_urlencode($v)); return implode('-',$parts); } function rewrite_next_parameter($querystr) { list($key,$rawvalue)=explode('-',$querystr,2); $value=''; for ($di=0;$di<strlen($rawvalue);) { if (substr($rawvalue,$di,2)=='--') { $di+=2; $value.='-'; } else if ($rawvalue[$di]=='-') { $di++; break; } else $value.=$rawvalue[$di++]; } return array($key,$value,substr($rawvalue,$di)); } function rewrite_parse_str($querystr) { $arr=array(); while ($querystr) { list($key,$value,$querystr)=rewrite_next_parameter($querystr); array_push($arr,urlencode($key).'='.urlencode($value)); } parse_str(implode('&',$arr),$output); return $output; } function rewrite_parse_url($url) { $parts=parseURL($url); $basepath=basename($parts['path']); if (substr($basepath,0,3)=='qx-' && substr($basepath,-5)=='.html') { $querystr=substr($basepath,3,strlen($basepath)-8); $parts['query'].=($parts['query']?'&':'').http_build_query(rewrite_parse_str($querystr)); $parts['path']=dirname_ending_with_slash($parts['path']); } return $parts; } function rewrite_command_query_parameters() { $arr=rewrite_parse_str($_GET['xquery']); unset($_GET['xquery']); unset($_REQUEST['xquery']); $_GET=array_merge($_GET,$arr); $_REQUEST=array_merge($_REQUEST,$arr); } function rewrite_fix_path($path) { $basename=basename($path); if (substr($basename,0,3)=='qx-' && substr($basename,-5)=='.html'); else if (substr($path,-1)!='/') $path.='/'; return $path; } ?>