<?php

     error_reporting(E_ALL & ~E_NOTICE);
// You must create a blank file called localfile_1192.xml in the same
// folder as this script. It MUST be writable by the 
// server. On unix you can CHMOD 666. On Windows
// you will need to access your custom control panel to set
// the permissions or contact your hosting company.
$LOCAL_XML_FILE = "localfile_1192.xml";
	
	if( !file_exists($LOCAL_XML_FILE) ) die("LinksTrade script error: $LOCAL_XML_FILE does not exist. Please create a blank file in the right folder called $LOCAL_XML_FILE.");
	if( !is_writable($LOCAL_XML_FILE) ) die("LinksTrade script error: $LOCAL_XML_FILE is not writable. Please set write permissions on $LOCAL_XML_FILE.");

	if( filemtime($LOCAL_XML_FILE) < (time() - 3600) || filesize($LOCAL_XML_FILE) < 50||$lt_ref==1) {
	$retrievedhtml="";
	$l_url=$_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
	if(function_exists("curl_init")) {
		    $ch = curl_init();
		   
		      curl_setopt ($ch, CURLOPT_URL, "http://www.linkstrade.net/linkstrade.php?lt_id=1192&l_url=$l_url");
		      curl_setopt ($ch, CURLOPT_HEADER, 0);
		   
		      ob_start();
		   
		      curl_exec ($ch);
		      curl_close ($ch);
		      $retrievedhtml = ob_get_contents();
		   
		      ob_end_clean();
		      
	   
} else
	if ($dh = @fopen("http://www.linkstrade.net/linkstrade.php?lt_id=1192&l_url=$l_url","r")) {
	      while (!feof($dh)) {
	     $retrievedhtml .= fread($dh,8192);
    }
    }
    if ($handle = fopen($LOCAL_XML_FILE, "w")) {
			fwrite($handle, $retrievedhtml);
			fclose($handle);
	}
	}


$xml  = "";
	if($handle = fopen($LOCAL_XML_FILE, "r")){
		$xml  = fread($handle, filesize($LOCAL_XML_FILE)+1);
		fclose($handle);
	}

	
 $parser = xml_parser_create();
    xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
    xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
    xml_parse_into_struct($parser,$xml,$d_ar,$i_ar);
    xml_parser_free($parser);
     $column=2;
 
for($i=0; $i<count($i_ar["item"]); $i++) {
	    
	      if($d_ar[$i_ar["item"][$i]]["type"]=="open") {
	    
	        for($j=$i_ar["item"][$i]; $j<$i_ar["item"][$i+1]; $j++) {
	
	    if($d_ar[$j]["tag"] == "title"){
	            $title = $d_ar[$j]["value"];
	          }
	          elseif($d_ar[$j]["tag"] == "link"){
	            $link = $d_ar[$j]["value"];
	          }
	      }
	     

  $links_arr[] = array("link" =>$link,"title" => $title);
        
        
        
   } 
  

}


echo "<table style='border: 1px solid #000000; border-spacing: 0px;background-color: #FFFFFF ' width=450 cellspacing=0 cellpadding=4 >";


	 $columns = 3;
		$count = 0;
		while ($links_arr[$count]["link"]) {
			echo "<tr>";
			for ($i = 1; $i <= $columns; $i++) {
				print "<td> <a href=".$links_arr[$count]["link"]." style='font-size:10; color:#000000;font-family:Verdana'>".$links_arr[$count]["title"]."</a> " .  "</td>";
				$count++;
		  	}
		  	echo "</tr>";
		}
		echo "<tr><td colspan=3 align=right><a href=http://www.linkstrade.net style='font-size:10; color:#000000;font-family:Verdana'>add your links</a></td></tr>";
		echo "</table>";?>