Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/xml_view.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');
include('translate.php');
$lang=$_REQUEST['lang'];
$id=$_REQUEST['cat_id'];

$comdate=date("Y-m-d")." ".date("H:i:s");

include("spotnews_qry.php");
$comp_id=$xml_id_new_S.$xml_id_S;


include("readalso_qry.php");
$comp_id_r=$xml_id_new_r.$xml_id_r;


include("allnews_qry.php");

$newid_X=trim($tot_all_news__,",");
$id_X=trim($tot_all_news__,",");


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,hour desc";
	$xml_res_new=$pg_sql->query_pass($xml_qry_new,"4");

}

if($id!=""){
	$rss_cat_name="select * from category where category_id='$id'";
	$rss_cat_name_res=$pg_sql->query_pass($rss_cat_name,"4");
	$rss_catname=$rss_cat_name_res[0]['category_name'];
}
if($rss_catname!="")
{
   $theme=eregi_replace("é","&#233;",$rss_catname);

   $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;");


							$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($rss_catname).".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>";
     $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]);
     $copy=trim($xml_res[$i][copyright]);
     $webmaster=trim($xml_res[$i][webmaster]);

     $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);

     $desc=str_replace("‘","‘",$desc);
     $desc=str_replace("’","’",$desc);
     $desc=eregi_replace("é","é",$desc);
     $desc=eregi_replace("É","é",$desc);
     $desc=eregi_replace("&amp;#xEB;","ë",$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($pubdate!="")
			$xmlString .="<pubDate>".$formatted."</pubDate>";

		 $xmlString .="</item>";

	}
   }


  for($j=0;$j<count($xml_res_new);$j++)
  {

        $title_=trim($xml_res_new[$j]['title']);
        $intro_=trim(strip_tags($xml_res_new[$j]['introtext']));
        $desc_=trim($xml_res_new[$j]['body']);
        $new_desc=strip_tags($intro_)."&lt;br&gt;".strip_tags($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_);
         $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");
	    if(is_writeable($filename))
	    {
	             fwrite($filePtr,$xmlString);
	             fclose($filePtr);
	    }

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

?>
Return current item: News Manager - RSS aggregator