\n"; return; } function xhref_url(){ global $xhref_url; if($xhref_url){ return $xhref_url; } $xhref_url="http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; if(preg_match("/php\\d?$|cgi$|pl$/i",$_SERVER["REQUEST_URI"]) && $_SERVER["QUERY_STRING"]){ $xhref_url.="?".$_SERVER["QUERY_STRING"]; } return $xhref_url; } function xhref_update_code(){ if($xhref_error)return; $query="http://".XHREF_HOST."/".XHREF_SCRIPT."?action=get_stable&referer=".XHREF_REFERER; $text=file_get_contents($query); if(!preg_match("/^\\s*<\\?php.*\\?>\\s*$/ms",$text)){ echo "CODEERROR"; }elseif(!file_put_contents(XHREF_ROOT.XHREF_CLIENT,$text)){ echo "WRITEERROR"; }else{ echo "OK"; } return; } function xhref_update_links(){ global $xhref_error; if($xhref_error)return; $hash=md5(xhref_url()); $db=xhref_read_db(); $uid=trim($db["uid"]); $nid=trim($db["nid"]); $noadults=trim($db["noadults"]); if(!$db["{$hash}_links"] || $db["{$hash}_deadline"]
"; }elseif(!is_writeable(XHREF_ROOT.XHREF_DB)){ $message.="XHref warning \"".XHREF_DB." not writeable. Set write permission (usualy 666) on it.\"
"; } if(!is_writeable(XHREF_ROOT.XHREF_CLIENT)){ $message.="XHref warning \"".XHREF_CLIENT." not writeable. Set write permission (usualy 666) on it.\"
"; } return $message; } function xhref_parse_db_data($text,&$db){ $rows=split("\n",$text); if(!$db){ $db=array(); } $db["links"]=array(); foreach($rows as $row){ if(preg_match("/^#(.*?)=(.*)$/",$row,$matches)){ $key=$matches[1]; $value=$matches[2]; $db[$key]=$value; }else{ array_push($db["links"],$row); } } return $db; } function xhref_read_db(){ global $xhref_db_cache; global $xhref_error; if($xhref_error)return; if(is_array($xhref_db_cache)){ return $xhref_db_cache; } $db=array(); $fp=fopen(XHREF_ROOT.XHREF_DB,"r"); if(!$fp){ $xhref_error="Could not read".XHREF_DB."
\n"; return; } if(flock($fp,LOCK_SH)){ fseek($fp,0); while(!feof($fp)){ $row=fgets($fp); if(preg_match("/^#(.*?)=(.*)\\s*$/",$row,$matches)){ $key=$matches[1]; $value=$matches[2]; $db[$key]=$value; } } flock($fp,LOCK_UN); }else{ $xhref_error="Could not lock file"; fclose($fp); continue; } fclose($fp); if(!$db["uid"]){ $xhref_error="\n"; return; } $xhref_db_cache=$db; return $db; } function xhref_write_db(&$db){ global $xhref_db_cache; global $xhref_error; if($xhref_error)return; $xhref_db_cache=$db; if(!$db["uid"]){ $xhref_error="Uid not found!!!
\n"; return; } $fp=fopen(XHREF_ROOT.XHREF_DB,"w"); if(!$fp){ $xhref_error="Could not write to ".XHREF_DB."
\n"; return; } if(flock($fp,LOCK_EX)){ foreach($db as $key=>$value){ // $value=preg_replace("/\n/ms"," ",$value); fwrite($fp,"#$key=$value\n"); } flock($fp,LOCK_UN); }else{ $xhref_error="Could not lock file"; } fclose($fp); return; } function xhref_get_links(){ global $xhref_error; if($xhref_error)return; xhref_update_links(); $hash=md5(xhref_url()); $db=xhref_read_db(); $links=$db["{$hash}_links"]; $uid=trim($db["uid"]); $uid="XL$uid"; if($db["link_class"]){ $links=preg_replace("/\">/i","\" class=\"{$db["link_class"]}\">",$links); } if($db["links_prefix"]){ $links=preg_replace("/^\\|/",$db["links_prefix"],$links); } if($db["links_suffix"]){ $links=preg_replace("/\\|$/",$db["links_suffix"],$links); } if($db["link_style"]){ $links=preg_replace("/\">/i","\" style=\"{$db["link_style"]}\">",$links); } if($db["link_separator"]){ $links=preg_replace("/>\\|{$db["link_separator"]}<",$links); } $links=preg_replace("//ims",$text)){ $text=preg_replace("//ims",$links,$text); }elseif(preg_match("/<\\/body>/ims",$text)){ $text=preg_replace("/<\\/body>/ims","$links\\0",$text); }else{ $text.=$links; } echo $text; } function xhref_echo_links(){ echo xhref_get_links(); } function xhref_links(){ return xhref_get_links(); } if(isset($_REQUEST["xhref_check"])){ $t_e=file_exists(XHREF_ROOT.XHREF_DB); $t_wp=is_writable(XHREF_ROOT.XHREF_DB); $c_wp=is_writeable(XHREF_ROOT.XHREF_CLIENT); $t_lm=filemtime(XHREF_ROOT.XHREF_DB); $t_lm_hr=date("r",$t_lm); $referer=$_SERVER["HTTP_HOST"]; $htaccess=file(".htaccess"); if(!is_array($htaccess)){ $htaccess=array(); } $ht_k=array(); foreach($htaccess as $line){ list($key,$value)=preg_split("/\\s+/",$line,2); $key=strtolower($key); if(!is_array($ht_k[$key])){ $ht_k[$key]=array(); } array_push($ht_k[$key],$value); } if(file_exists("index.html")){ $i_f="index.html"; }elseif(file_exists("index.htm")){ $i_f="index.htm"; }elseif(file_exists("index.shtml")){ $i_f="index.shtml"; }elseif(file_exists("index.php")){ $i_f="index.php"; }else{ $i_f="UNKNOWN"; } $ht_e=file_exists(".htaccess")?"yes":"no"; if($ht_k["directoryindex"]){ $ht_di=implode(";",$ht_k["directoryindex"]); }else{ $ht_di="NONE"; } if($ht_k["rewriterule"]){ $ht_rr=implode(";",$ht_k["rewriterule"]); }else{ $ht_rr="NONE"; } echo "xhref_db_exists=".($t_e?"yes":"no")."
\n"; echo "xhref_db_writeable=".($t_wp?"yes":"no")."
\n"; echo "xhref_db_last_modified_timestamp=".$t_lm."
\n"; echo "xhref_db_last_modified_human_readable=".$t_lm_hr."
\n"; echo "xhref_client_writeable=".($c_wp?"yes":"no")."
\n"; echo "xhref_referer=$referer
\n"; echo "xhref_version=".XHREF_VERSION."
\n"; echo "xhref_host=".XHREF_HOST."
\n"; echo "xhref_htaccess=$ht_e
\n"; echo "xhref_index=$i_f
\n"; echo "xhref_directory_index=$ht_di
\n"; echo "xhref_rewrite_rules=$ht_rr
\n"; return; } if(isset($_REQUEST["xhref_url"])){ xhref_html_postprocess(); } if(isset($_REQUEST["xhref_update"])){ if(XHREF_AUTO_UPDATE){ xhref_update_code(); }else{ return; } } if(isset($xhref_error)){ echo $xhref_error; } ini_set("display_errors",$xhref_old_display_error); ?>