Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/xml.php
<?php
	/*******************************************************************************
     **  File          :  xml_view.php                                            **
     **  Author        :  G.Ramkumar                                              **
     **  Description   :  Xml view			 									  **
  	 **  Date          :  14/07/2005                                              **
     **  Last Modified :  02/08/2005                                              **
     **  PHP Version   :  5.0.3                                                   **
     **                                                                           **
     *******************************************************************************/
include('db/dbconnect.php');
$newid_X=base64_decode($_REQUEST['new_id']);
$id_X=base64_decode($_REQUEST['id']);

if($id_X!="")
{
	$xml_qry="select * from rssurl_newsitem where url_newsitem_id in ($id_X) order by pubtime desc";
	$xml_res=$pg_sql->query_pass($xml_qry,"4");

}
if($newid_X!="")
{
	$xml_qry_new="select * from new_newsitem where newsitem_id in ($newid_X) order by pubdate desc";
	$xml_res_new=$pg_sql->query_pass($xml_qry_new,"4");

}

if($xml_res[0]['language']!="")
 $lang=$xml_res[0]['language'];
elseif($xml_res_new[0]['language']!="")
 $lang=$xml_res_new[0]['language'];
else
 $lang="";

if($_REQUEST['channel']!=''){
  if(!is_dir('xml'))
	mkdir('xml',0777);
 
 $_REQUEST['channel']=str_replace("/","_",$_REQUEST['channel']);
 $_REQUEST['channel']=str_replace(" ","_",$_REQUEST['channel']);
  $filename="xml/".$_REQUEST['channel'].".xml"; 
}else{
	if($_REQUEST['theme']!="")
	{
	   $theme=eregi_replace("é","&#233;",$_REQUEST['theme']);

	   $titarr = array("&Atilde;","£","&Acirc;","&micro;","¼","&middot;","&acute;","&sup3;","&brvbar;","&para;","&reg;","&macr;","&yen;","&uml;","&deg;","&iquest;","&Auml;","&iexcl;","&cent;",
							   "&curren;","&copy;","&sect;","&ordf;","&laquo;","&not;","&plusmn;","&sup2;","&sup1;","&cedil;",
							   "&ordm;","&raquo;","½","¾","&Agrave;","&Aacute;","&Aring;","&AElig;","&Ccedil;",
							   "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ETH;","&Ntilde;",
							   "&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;","&Oslash;","&Ugrave;","&Uacute;","&Ucirc;",
							   "&Uuml;","&Yacute;","&THORN;","ß","à","á","&atilde;","&auml;","&aring;","&aelig;",
							   "ç","è","é","ê","ë","&igrave;","&iacute;","î","&iuml;","&eth;","&ntilde;","&ograve;",
							   "&oacute;","ô","&otilde;","&ouml;","&divide;","&oslash;","&ugrave;","&uacute;","&ucirc;","&yacute;","&thorn;","&yuml;","&#euro;","&shy;","&nbsp;","ü","‘","’","â","–",
							   "Œ","œ","Š","š","Ÿ","ƒ","—","–","“","”");

	   $titarr_ = array("&#195;","&#163;","&#194;","&#181;","&#188;","&#183;","&#180;","&#179;","&#166;","&#182;","&#174;","&#175;","&#165;","&#168;","&#176;","&#191;","&#196;","&#161;","&#162;","&#164;",
							   "&#169;","&#167;","&#170;","&#171;","&#172;","&#177;","&#178;","&#185;","&#184;","&#186;","&#187;","&#189;",
							   "&#190;","&#192;","&#193;","&#194;","&#197;","&#198;","&#199;","&#200;","&#201;","&#202;","&#203;","&#204;",
							   "&#205;","&#206;","&#207;","&#208;","&#209;","&#210;","&#211;","&#212;","&#213;","&#214;","&#215;","&#216;",
							   "&#217;","&#218;","&#219;","&#220;","&#221;","&#222;","&#223;","&#224;","&#225;","&#227;","&#228;","&#229;",
							   "&#230;","&#231;","&#232;","&#233;","&#234;","&#235;","&#236;","&#237;","&#238;","&#239;","&#240;","&#241;","&#242;",
							   "&#243;","&#244;","&#245;","&#246;","&#247;","&#248;","&#249;","&#250;","&#251;","&#253;","&#254;","&#255;","&#8364;","&#173;","&#160;","&#252;","&#8216;","&#8217;","&#226;","&#45;",
							   "&#338;","&#339;","&#352;","&#353;","&#376;","&#402;","&#8212;","&#8211;","&#8220;","&#8221;");


								$t=0;
								foreach ($titarr as $element)
								{
									$theme = eregi_replace($element,$titarr_[$t],$theme);
									$t = $t + 1;

								}
	  if(!is_dir($lang))
		mkdir($lang,0777);

	  $filename=$lang."/".strtolower($_REQUEST['theme']).".xml";
	  $theme_name="/".strtolower($theme);

	}else{
	  $filename=$lang.".xml";
	}
}
  	 header("Content-type: text/xml");

	 $xmlString  ='<?xml version="1.0" encoding="utf-8" ?>';
	 $xmlString .='<rss version="2.0">';
     $xmlString .="<channel>";
     $xmlString .="<title>http://news.belgium.be".$theme_name."</title>";
     $xmlString .="<link>http://news.belgium.be</link>";
     $xmlString .="<image><title>News.Belgium.be</title><url>http://newsmanager.avalonnet.com/images/logo_final_en.jpg</url>";
     $xmlString .="<link>http://news.belgium.be</link>";
     $xmlString .="</image>";
     $xmlString .="<description>news.belgium.be</description>";


	 if($lang!="")
       $xmlString .="<language>".$lang."</language>";

  for($i=0;$i<count($xml_res);$i++)
   {
     $title=str_replace("||","'",$xml_res[$i][news_title]);
     $image=trim($xml_res[$i][image]);
     $desc=str_replace("||","'",$xml_res[$i][description]);
     $url=trim($xml_res[$i][url]);
     $author=trim($xml_res[$i][author]);
     //$pubdate=trim($xml_res[$i][pubdate]);
     $pubdate=trim($xml_res[$i][pubtime]);
     $timestamp = $pubdate;
	 $formatted = date('r', strtotime($timestamp));

     $lastdate=trim($xml_res[$i][last_builddate]);
     $hour=trim($xml_res[$i][hour]);
     $category=trim($xml_res[$i][category]);
     $copy=trim($xml_res[$i][copyright]);
     $webmaster=trim($xml_res[$i][webmaster]);
     $enclosure=trim($xml_res[$i][enclosure]);

     $title=eregi_replace("é","é",$title);
   	 $title=eregi_replace("É","é",$title);
     $title=str_replace("‘","‘",$title);
     $title=str_replace("’","’",$title);
     $title=str_replace("ß","à",$title);
     $title=str_replace("…","...",$title);
     $title=str_replace("“","”",$title);
     $title=str_replace("”","”",$title);
     $title=str_replace("&amp;#039;","'",$title);



     $desc=str_replace("‘","‘",$desc);
     $desc=str_replace("’","’",$desc);
     $desc=eregi_replace("é","é",$desc);
     $desc=eregi_replace("É","é",$desc);
     $desc=eregi_replace("&amp;#xEB;","ë",$desc);
     $desc=str_replace("ß","à",$desc);



		$arr1 = array("&Atilde;","£","&Acirc;","&micro;","¼","&middot;","&acute;","&sup3;","&brvbar;","&para;","&reg;","&macr;","&yen;","&uml;","&deg;","&iquest;","&Auml;","&iexcl;","&cent;",
   		 		       "&curren;","&copy;","&sect;","&ordf;","&laquo;","&not;","&plusmn;","&sup2;","&sup1;","&cedil;",
   		               "&ordm;","&raquo;","½","¾","&Agrave;","&Aacute;","&Aring;","&AElig;","&Ccedil;",
   		               "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ETH;","&Ntilde;",
   		               "&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;","&Oslash;","&Ugrave;","&Uacute;","&Ucirc;",
   		               "&Uuml;","&Yacute;","&THORN;","ß","à","á","&atilde;","&auml;","&aring;","&aelig;",
   		               "ç","è","&eacute;","ê","ë","&igrave;","&iacute;","î","&iuml;","&eth;","&ntilde;","&ograve;",
   		               "&oacute;","ô","&otilde;","&ouml;","&divide;","&oslash;","&ugrave;","&uacute;","&ucirc;","&yacute;","&thorn;","&yuml;","&#euro;","&shy;","&nbsp;","ü","‘","’","â","–",
   		               "Œ","œ","Š","š","Ÿ","ƒ","—","–");

   		$arr2 = array("&#195;","&#163;","&#194;","&#181;","&#188;","&#183;","&#180;","&#179;","&#166;","&#182;","&#174;","&#175;","&#165;","&#168;","&#176;","&#191;","&#196;","&#161;","&#162;","&#164;",
   		 	           "&#169;","&#167;","&#170;","&#171;","&#172;","&#177;","&#178;","&#185;","&#184;","&#186;","&#187;","&#189;",
   		               "&#190;","&#192;","&#193;","&#194;","&#197;","&#198;","&#199;","&#200;","&#201;","&#202;","&#203;","&#204;",
   		               "&#205;","&#206;","&#207;","&#208;","&#209;","&#210;","&#211;","&#212;","&#213;","&#214;","&#215;","&#216;",
   		               "&#217;","&#218;","&#219;","&#220;","&#221;","&#222;","&#223;","&#224;","&#225;","&#227;","&#228;","&#229;",
   		               "&#230;","&#231;","&#232;","&#233;","&#234;","&#235;","&#236;","&#237;","&#238;","&#239;","&#240;","&#241;","&#242;",
   		               "&#243;","&#244;","&#245;","&#246;","&#247;","&#248;","&#249;","&#250;","&#251;","&#253;","&#254;","&#255;","&#8364;","&#173;","&#160;","&#252;","&#8216;","&#8217;","&#226;","&#45;",
   		               "&#338;","&#339;","&#352;","&#353;","&#376;","&#402;","&#8212;","&#8211;");


		                    $j=0;
		 					foreach ($arr1 as $element)
		 					{
		 						$title = eregi_replace($element,$arr2[$j],$title);
		 						$desc = eregi_replace($element,$arr2[$j],$desc);
		 						$j = $j + 1;

		 					}

	if($title!="")
	{
		 $xmlString .="<item>";

		 $xmlString .="<title>".$title."</title>";
		 if($desc!="")
		   $xmlString .="<description>".$desc."</description>";
		 if($url!=""){
		 		if(strstr($url,"http://"))
		           $url=$url;
		         else
		            $url="http://".$url;

		   		$xmlString .="<link>".$url."</link>";
		   }
		 if($image!="")
			$xmlString .="<image>".$image."</image>";
		 if($author!="")
			$xmlString .="<author>".$author."</author>";
		 if($enclosure!="")
		 	$xmlString .="<enclosure>".$enclosure."</enclosure>";
		 if($category!="")
		    $xmlString .="<category>".$category."</category>";		 
		if($pubdate!="")
			$xmlString .="<pubDate>".$formatted."</pubDate>";
		/*
		if($lastdate!="")
			$xmlString .="<lastbuilddate>".$lastdate."</lastbuilddate>";
		 if($hour!="")
			$xmlString .="<hour>".$hour."</hour>";
		 if($copy!="")
			$xmlString .="<copyright>".$copy."</copyright>";
		 if($webmaster!="")
		   $xmlString .="<webmaster>".$webmaster."</webmaster>";
         */
		 $xmlString .="</item>";

	}
   }


  for($j=0;$j<count($xml_res_new);$j++)
  {
        $title_=trim($xml_res_new[$j]['title']);
        $intro_=strip_tags(trim($xml_res_new[$j]['introtext']));
        $desc_=strip_tags(trim($xml_res_new[$j]['body']));
        $new_desc=$intro_."&lt;br&gt;".$desc_;
        $pubdate_=trim($xml_res_new[$j]['pubdate']);
        $hour_=trim($xml_res_new[$j]['hour']);
        if($hour_!="")
          $hour_=$hour_.":00";

        $pubtime_=$pubdate_." ".$hour_;

        $timestamp_=date("r",strtotime($pubtime_));

        $url_=trim($xml_res_new[$j]['url_external']);
        $new_desc=str_replace("&nbsp;"," ",$new_desc);

        $title_=eregi_replace("é","é",$title_);
		$title_=eregi_replace("É","é",$title_);
		$title_=str_replace("‘","‘",$title_);
		$title_=str_replace("’","’",$title_);
		$title_=str_replace("“","”",$title_);
        $title_=str_replace("”","”",$title_);

		$new_desc=str_replace("‘","‘",$new_desc);
		$new_desc=str_replace("’","’",$new_desc);
		$new_desc=eregi_replace("é","é",$new_desc);
		$new_desc=eregi_replace("É","é",$new_desc);
     	$new_desc=eregi_replace("&amp;#xEB;","ë",$new_desc);


        $arr1_ = array("&Atilde;","£","&Acirc;","&micro;","¼","&middot;","&acute;","&sup3;","&brvbar;","&para;","&reg;","&macr;","&yen;","&uml;","&deg;","&iquest;","&Auml;","&iexcl;","&cent;",
   		 		       "&curren;","&copy;","&sect;","&ordf;","&laquo;","&not;","&plusmn;","&sup2;","&sup1;","&cedil;",
   		               "&ordm;","&raquo;","½","¾","&Agrave;","&Aacute;","&Aring;","&AElig;","&Ccedil;",
   		               "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;","&ETH;","&Ntilde;",
   		               "&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;","&Oslash;","&Ugrave;","&Uacute;","&Ucirc;",
   		               "&Uuml;","&Yacute;","&THORN;","ß","à","á","&atilde;","&auml;","&aring;","&aelig;",
   		               "ç","è","&eacute;","ê","&igrave;","&iacute;","î","&iuml;","&eth;","&ntilde;","&ograve;",
   		               "&oacute;","ô","&otilde;","&ouml;","&divide;","&oslash;","&ugrave;","&uacute;","&ucirc;","&yacute;","&thorn;","&yuml;","&#euro;","&shy;","&nbsp;","ü","‘","’","â","–",
   		               "Œ","œ","Š","š","Ÿ","ƒ","—");

   		$arr2_ = array("&#195;","&#163;","&#194;","&#181;","&#188;","&#183;","&#180;","&#179;","&#166;","&#182;","&#174;","&#175;","&#165;","&#168;","&#176;","&#191;","&#196;","&#161;","&#162;","&#164;",
   		 	           "&#169;","&#167;","&#170;","&#171;","&#172;","&#177;","&#178;","&#185;","&#184;","&#186;","&#187;","&#189;",
   		               "&#190;","&#192;","&#193;","&#194;","&#197;","&#198;","&#199;","&#200;","&#201;","&#202;","&#203;","&#204;",
   		               "&#205;","&#206;","&#207;","&#208;","&#209;","&#210;","&#211;","&#212;","&#213;","&#214;","&#215;","&#216;",
   		               "&#217;","&#218;","&#219;","&#220;","&#221;","&#222;","&#223;","&#224;","&#225;","&#227;","&#228;","&#229;",
   		               "&#230;","&#231;","&#232;","&#233;","&#234;","&#235;","&#236;","&#237;","&#238;","&#239;","&#240;","&#241;","&#242;",
   		               "&#243;","&#244;","&#245;","&#246;","&#247;","&#248;","&#249;","&#250;","&#251;","&#253;","&#254;","&#255;","&#8364;","&#173;","&#160;","&#252;","&#8216;","&#8217;","&#226;","&#45;",
   		               "&#338;","&#339;","&#352;","&#353;","&#376;","&#402;","&#8212;");


   		  $k=0;
   		 					foreach ($arr1_ as $element_)
   		 					{
   		 						$title_ = eregi_replace($element_,$arr2_[$k],$title_);
   		 						$new_desc = eregi_replace($element_,$arr2_[$k],$new_desc);
   		 						$k = $k + 1;

   		 					}


 		$xmlString .="<item>";
 		$xmlString .="<title>".$title_."</title>";
   		$xmlString .="<description>".$new_desc."</description>";
   		if($url_!=""){
   		  if(strstr($url_,"http://"))
		     $url_=$url_;
		  else
		    $url_="http://".$url_;

   		 	$xmlString .="<link>".$url_."</link>";
   		 }


   		if($pubdate_!="")
   		  $xmlString .="<pubDate>".$timestamp_."</pubDate>";

		 $xmlString .="</item>";

  }
     $xmlString .="</channel>";
     $xmlString .="</rss>";


   $filePtr=fopen($filename,"wb") or die("can't open file");
   if(is_writeable($filename))
   {
            fwrite($filePtr,$xmlString);
            fclose($filePtr);
   }

 header("Location: ".$filename);
 exit;

?>
Return current item: News Manager - RSS aggregator