<?

  //  ini_set('display_errors','on');

	include_once('../inc/functions.inc.php');


//	$cache_query = str_replace(' ','',$_GET[query].'.'.$_GET[p]);
	$cache_file = '../../_cache/searched/searched_'.date('Ymdh').'.txt';


 //	echo "file ".$cache_file." mod.". date ("Y-m-d H:i:s", filemtime($cache_file));


	// teraz unlink($cache_file);
	remove_old(5, $cache_file);


	if(!file_exists($cache_file)) {

	$qs1="select query FROM searched ORDER BY rand() LIMIT 80"; 
	$rs1=mysql_query($qs1);
 
	while($line1 = mysql_fetch_assoc($rs1)) {
		$ALL_DANE1[] = $line1;
	}

 
 		
	 // 	echo "write cache!!";

				$handlex2 = fopen($cache_file, "w");
				fwrite($handlex2, serialize($ALL_DANE1));
				fclose($handlex2);	

	} else {
/*
	 //	echo "open cache!!";

		$handle = fopen($cache_file, "r");
		$contents = fread($handle, filesize($cache_file));
		fclose($handle);	
 
		$ALL_DANE1 = unserialize($contents);

//print_r($ALL_DANE);
*/
	}



		$handle = fopen($cache_file, "r");
		$contents = fread($handle, filesize($cache_file));
		fclose($handle);	
 
		$ALL_DANE1 = unserialize($contents);



//print_r($ALL_DANE1);

	$ALL_DANE1[][query] = 'japanese tattoo symbols';
	shuffle($ALL_DANE1);

$t_i=0; 
$t_przec=$t_keys=''; 
	foreach($ALL_DANE1 as $line1) {

	if ($line1[query] == '' && $line1[keyword] !='') $line1[query] = $line1[keyword];
	
	$t_keys .= $t_przec."'".addslashes($line1[query])."'";
	$t_przec=',';
		if($t_i < 100){
			$t_i++;
			$keys[$t_i]=$line1[query];
		}	
		
	}

$domena = 'www.pictorati.com';
$MAIN_DOMAIN = $domena;
$site_title = 'Pictorati: Popular searches';
  
  $lastmod_atom = date('Y-m-d\TH:i:s',strtotime("-1 day")).''.$timezone;// $usec.
  $lastmod = date("D, j M Y H:i:s O"); //.'.'.$usec.$timezone;


$simple_xml_start = "<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' version='2.0'>
<channel>
<atom:link href='http://$domena/xml/popular.xml' rel='self' type='application/rss+xml' />
<atom:id>tag:".$MAIN_DOMAIN.",".date('Y').":pictorati-".date('YmdHis')."</atom:id>
<title>".$MAIN_DOMAIN."</title>
<description>Latest popular searches</description>
<image><title>Pictorati: Popular Searches</title><url>http://www.pictorati.com/i/logo_pictorati_head.gif</url><link>http://www.pictorati.com/</link></image>
<link>http://www.pictorati.com</link>
<generator>Pictorati.com</generator>
";
/*
<lastBuildDate>$lastmod</lastBuildDate>

<openSearch:totalResults>$ilosc</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>30</openSearch:itemsPerPage>
*/

// <managingEditor>$site_title</managingEditor>


$simple_xml ='';

$simple_xml_end = "</channel>
</rss>";



  for($i=1;$i<=80;$i++){ 


$simple_xml .= '<item>
<title><![CDATA[' . $keys[$i] . ']]></title>
<link><![CDATA[http://www.pictorati.com/search.htm?query=' . urlencode($keys[$i]) . ']]></link>
<guid><![CDATA[http://www.pictorati.com/search.htm?query=' . urlencode($keys[$i]) . ']]></guid>
</item>';


  }


header("Content-type: application/xml");
echo $simple_xml_start.$simple_xml.$simple_xml_end;



