<?

/*
  IT.PStudio /internet solutions/ - http://www.itpstudio.net
  Copyright (c) 1999-2010 webStudio [:] All rights reserved
*/

require('inc/head.conf.php');


if ((isset($_SERVER["HTTP_ACCEPT"]) and
stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) or
stristr($_SERVER["HTTP_USER_AGENT"], "W3C_Validator") )
{
header("Content-type: application/xhtml+xml");
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
}
else
{
header("Content-type: text/html; charset=utf-8");
}


//$questionmark = "?";
//echo "<".$questionmark."xml version=\"1.0\" encoding=\"utf-8\"".$questionmark.">\n";
echo'
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';





			
				
function print_tree_sitemap($parent_id, &$parent_node, $level=0, $unlinks = array()){
        global $tree, $items, $parents;
        //if (!in_array($parent_id, $parents)) return false;
        if (is_array($tree[$parent_id])) {
                foreach ($tree[$parent_id] as $item){
                        $node = print_item_sitemap($item, $parent_node, $level, $unlinks);
                        print_tree_sitemap($item['sites_id'], $node, $level+1, $unlinks);
                        }
       }
}

function print_item_sitemap(&$item, &$parent_node, $level=0, $unlinks = array()) {
        global $tree, $treec;

/*wglebienie 0*/
       if ($level == 0) {
        if($item['sites_id'] == PAGE_HOME && LANG == F_LANG) 
	   $class = "1.00";
        else
        $class = "0.80";
	   }
	   
/*wglebienie 1*/
	   if ($level == 1) { 
	   $class = "0.70";
	   }
        
/*wglebienie 2*/
	   if ($level == 2) { 
	   $class = "0.60";
	   }
	   
/*wglebienie 3*/
	   if ($level == 3) { 
	   $class = "0.60";
	   }
	   
/*wglebienie >  3*/
	   if ($level > 3) { 
	   $class = "0.50";
	   }
        
	/*koneic wglebień */  
	   
       $lang  = (LANG==F_LANG)?"":"&l=".LANG;
        
       if ($item['sites_inmenu']!='0') { 
        
       if ($item['sites_linkout']!='0') { 
		 						  $linkto = $item['sites_link']; 
		 						  $targetto = '_blank';
		 						 }
		 				    else { 
		 				    	    //$url = eregi("http://([a-zA-Z0-9_-])", $item['sites_link']);
			 				        //if ($url) {	
			 				       	if(filter_var($item['sites_link'], FILTER_VALIDATE_URL)) {
			 				    				   $linkto = $item['sites_link'];
		 				    					 }	
		 				    				else { $linkto = HTTP_WWW.'/'.MAIN.'?id='. $item['sites_id'];
	 				    						 }

			 				      $targetto = '_self'; 
			 				     }
        $exists_subitems = (is_array($tree[$item['sites_id']]));


		//link bez polskich znaków, spacji itp 	
          
          
          $linkname = char_replace((($item['sites_title'])? $item['sites_title'] : $item['sites_subtitle']));
          if($item['sites_id'] == PAGE_HOME && LANG == F_LANG)
               $flink = '';
          else
               $flink = $linkname.','.$item['sites_id'].','.LANG.'.html';   

	
        $link   = (!in_array($item['sites_id'], $unlinks))?"<loc>".HTTP_WWW."/".$flink ."</loc>\n<priority>". $class." </priority>\n":"";
        
        
        if ($exists_subitems) { if ($item['sites_id'] == '1') { echo "<url>".$link."</url>\n"; }
        												 else { if ($item['sites_parent_id'] != '1') { $level=(NO_INDEX)?$level:$level-1; echo "<url>".$link."</url>\n"; } else { echo "<url>".$link."</url>\n"; } }
				  			  }
                         else { if ($item['sites_parent_id'] != '1') { $level=(NO_INDEX)?$level:$level-1; echo "<url>".$link."</url>\n"; } else { echo "<url>".$link."</url>\n"; }
				  			  }


			  			  }
}

// ------------------------------------------------------------------------
print_tree_sitemap(NO_INDEX, $tree, 0, array(0)); 
echo '</urlset>';
?>