Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/cat_allnews.php
<?php
	/*******************************************************************************
     **  File          :  cat_allnews.php                                         **
     **  Author        :  G.Ramkumar                                              **
     **  Description   :  Dispalying all news section and Query page			  **
  	 **  Date          :  14/09/2005                                              **
     **  Last Modified :  14/09/2005                                              **
     **  PHP Version   :  5.0.3                                                   **
     **                                                                           **
     *******************************************************************************/
$comdate=date("Y-m-d")." ".date("H:i:s");

$all_newcomp_id=trim($comp_id,",");

if($page_name_ =="index.php")
   include($read_xml_include);

if($_REQUEST['tot_exist_id']!="")
  $tot_exist_id=base64_decode($_REQUEST['tot_exist_id']);

if($all_newcomp_id!="" || $xml_id_r!="" || $xml_id_new_r!="")
{
  $tot_exist_id=$comp_id.$xml_id_r.$xml_id_new_r;
  $tot_exist_id=trim($tot_exist_id,",");
  $all_item_S="where pubdate <='$comdate' and newsitem_id not in (".$tot_exist_id.")";
}else{
  $all_item_S="";
}

 if($_REQUEST['cat_id']!="" && $_REQUEST['subcat_id']=="")
 {
    if($all_item_S!="")
       $all_catid ="and flag='Y' and  category_id=".$_REQUEST['cat_id'];
     else
       $all_catid ="where pubdate <='$comdate' and flag='Y' and category_id=".$_REQUEST['cat_id'];

  $allrsscat_qry="select * from category where category_id=".$_REQUEST['cat_id'];
  $allrsscat_qry_result=$pg_sql->query_pass($allrsscat_qry,"4");
  $allrss_cat_name="theme=".strtolower($allrsscat_qry_result[0]['category_name'])."&";

 }elseif($_REQUEST['cat_id']!="" && $_REQUEST['subcat_id']!="")
 {
   if($all_item_S!="")
     $all_catid ="and flag='Y' and subcategory_id=".$_REQUEST['subcat_id'];
   else
     $all_catid ="where pubdate <='$comdate' and flag='Y' and subcategory_id=".$_REQUEST['subcat_id'];

  $allsubrsscat_qry="select * from subcategory where subcategory_id=".$_REQUEST['subcat_id'];
  $allsubrsscat_qry_result=$pg_sql->query_pass($allsubrsscat_qry,"4");
  $allrss_cat_name="theme=".strtolower($allsubrsscat_qry_result[0]['subcategory_name'])."&";

 }
 else{
    $new_cat_qry="select * from category where language='$lang'";
    $new_cat_res=$pg_sql->query_pass($new_cat_qry,"4");

    $new_subcat_qry="select * from subcategory where language='$lang'";
    $new_subcat_res=$pg_sql->query_pass($new_subcat_qry,"4");

    for($y=0;$y<count($new_cat_res);$y++)
    {
      $N_catid .=$new_cat_res[$y][category_id].",";
    }
    for($z=0;$z<count($new_subcat_res);$z++)
	{
           if($new_subcat_res[$z][subcategory_id]!="")
	          $N_subcatid .=$new_subcat_res[$z][subcategory_id].",";
    }
    $N_catid=trim($N_catid,",");


    if($N_subcatid!="")
    {
       $N_subcatid=trim($N_subcatid,",");
       $N_qry = " or subcategory_id in (".$N_subcatid.")";
    }
    if($N_catid!="")
    {
       if($all_item_S!="")
         $all_catid="and flag='Y' and  category_id in (".$N_catid.")". $N_qry ;
       else
         $all_catid="where pubdate <='$comdate' and flag='Y' and category_id in (".$N_catid.")". $N_qry ;
    }
 }

 $Tot_all_news="select DISTINCT(newsitem_id),pubdate from newsitem_category $all_item_S  $all_catid order by pubdate desc";
 $Tot_res_=$pg_sql->query_pass($Tot_all_news,"4");
 $total_num =count($Tot_res_) ;

// Set limit display news item per page
 if($_REQUEST['offset']!="" && $_REQUEST['offset']!=0)
 {
   $limit = $allnews_item__;
 }else{
   $limit = $allnews_item_home__;
 }

   $offset = 0;
 if($_REQUEST['offset']>0)
  {
 	   $offset = $_REQUEST['offset'];
  }

$allnewsqry="select DISTINCT(newsitem_id),pubdate from newsitem_category $all_item_S $all_catid order by pubdate desc limit $limit offset $offset";
$allnews_res=$pg_sql->query_pass($allnewsqry,"4");
$all_cnt_=count($allnews_res);

for($b=0;$b<$all_cnt_;$b++)
{
    $xml_allnewsid=$allnews_res[$b][newsitem_id];

    $xml_all_news="select * from rssurl_newsitem where url_newsitem_id=$xml_allnewsid and frontend_export='Y' and language='$lang'";
    $xml_all_news_res=$pg_sql->query_pass($xml_all_news,"4");

	$xml_all_new_news="select * from new_newsitem where newsitem_id=$xml_allnewsid and frontend='Y' and language='$lang'";
	$xml_all_new_news_res=$pg_sql->query_pass($xml_all_new_news,"4");

	if($xml_all_news_res[0]['url_newsitem_id']!="")
	{
	   $xml_allid .=$xml_all_news_res[0]['url_newsitem_id'].",";
	   $xml_cnt_[]=$xml_all_news_res[0]['url_newsitem_id'];

	}
	if($xml_all_new_news_res[0]['newsitem_id']!="")
	{
	  $xml_allid_new .=$xml_all_new_news_res[0]['newsitem_id'].",";
	  $xml_cnt_[]=$xml_all_new_news_res[0]['newsitem_id'];

    }

}

?>
<table width="95%" border="0" height="100" cellspacing="0" cellpadding="0" align="center">
<?if(count($xml_cnt_)>0){?>
		<tr>
                <td valign="top" height="25">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="heading5" height="25"><?=$allnews_?></td>
                      <td align="right" valign="middle" class="heading5" height="25"><a target="_new" href="xml.php?<?=$allrss_cat_name?>id=<?=base64_encode(trim($xml_allid,","))?>&new_id=<?=base64_encode(trim($xml_allid_new,","))?>"><?if($display_style_==1){?><img src="images/rss-2.0.jpg" width="80" height="15" border="0" alt="Link to RSS Feed"><?}else{?><img src="images/<?=$rss_style_?>"  border="0" align="absmiddle" alt="Link to RSS Feed"><?}?></a>&nbsp;&nbsp;</td>
                    </tr>
                  </table>
                </td>
              </tr>
<?
}
for($a=0;$a<$all_cnt_;$a++)
{
    $allnewsid=$allnews_res[$a][newsitem_id];

    $all_news="select * from rssurl_newsitem where url_newsitem_id=$allnewsid and frontend_export='Y' and language='$lang' ";
    $all_news_res=$pg_sql->query_pass($all_news,"4");

	$all_new_news="select * from new_newsitem where newsitem_id=$allnewsid and frontend='Y' and language='$lang'";
	$all_new_news_res=$pg_sql->query_pass($all_new_news,"4");

     if($all_news_res[0]['url_newsitem_id']!="")
     {
         $all_id_=$all_news_res[0]['url_newsitem_id'];
         $hour_=str_replace(":","h",$all_news_res[0]['hour']);

		 $date=explode("-",$all_news_res[0]['pubdate']);
		 $date=$date[2]."/".$date[1]."/".$date[0];
		 $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
		 $yday=explode("/",$yesterday);
	     $ymon=$yday[1];

		 if(strlen(trim($yday[0]))==1)
			   $yday[0] ="0".trim($yday[0]);

		  $yesterday=trim($yday[0])."/".$ymon."/".$yday[2];
		  $today=date('d/m/Y');


		if($date==$today)
		 $pubdate_=$today_;
		elseif($date == $yesterday)
		 $pubdate_=$yesterday_;
		else
		 $pubdate_=$date;

  		  $title_=str_replace("||","'",$all_news_res[0]['news_title']);
		  $rep_title=$title_;
		  $rep_title=str_replace("é","é",$rep_title);
		  $rep_title=str_replace("’","’",$rep_title);
		  $rep_title=str_replace("è","è",$rep_title);
		  $rep_title=str_replace("Ã","à",$rep_title);
		  $rep_title=str_replace("àª","ê",$rep_title);
		  $rep_title=str_replace("‘","‘",$rep_title);
		  $rep_title=str_replace("à»","û",$rep_title);
		  $rep_title=str_replace("…","...",$rep_title);
    	  $rep_title=str_replace("&amp;#039;","'",$rep_title);


		  $title_=$rep_title;
		  $all_enclosure_=$all_news_res[0]['enclosure'];
          $feed_desc=strip_tags(html_entity_decode($all_news_res[0]['description']));
  		  $feed_rep_desc=$feed_desc;
 	 	  $feed_rep_desc=str_replace("é","é",$feed_rep_desc);
		  $feed_rep_desc=str_replace("’","’",$feed_rep_desc);
		  $feed_rep_desc=str_replace("è","è",$feed_rep_desc);
  		  $feed_rep_desc=str_replace("Ã","à",$feed_rep_desc);
 		  $feed_rep_desc=str_replace("àª","ê",$feed_rep_desc);
		  $feed_rep_desc=str_replace("‘","‘",$feed_rep_desc);
 		  $feed_rep_desc=str_replace("à»",û,$feed_rep_desc);
      	  $feed_desc=$feed_rep_desc;

  	  	 $feed_desc=str_replace("||","'",$feed_desc);

		if(strlen($feed_desc)>$length__){
		   $feed_desc=substr($feed_desc,0,$length__);
		   $feed_ex_intro=strrchr(trim($feed_desc)," ");
		   if($feed_ex_intro!=""){
 		   	  $feed_ex_new_str=explode($feed_ex_intro,$feed_desc);
		   	  $feed_desc=$feed_ex_new_str[0]."...";
		   	}
 		 }else{
		     $feed_desc=$feed_desc;
        }


?>
<tr>
	 <td valign="Top">
<?
		  if($all_enclosure_!="")
		   	  $all_en_play='<img src="images/Play1.jpg" border="0" alt="Play" onclick="Audio.URL=\''.$all_enclosure_.'\'; Audio.controls.play()" align="absmiddle" style="cursor:hand;">';
          else
            $all_en_play='';
?>
	     <a href="<?=$all_news_res[0]['url']?>" target="_new" class="contblue2"><?=$title_?></a>&nbsp;<?=$all_en_play?>
  	    <?if($display_allnews__==1 || $display_allnews__==2){?>
		 <font class="contgrey2"><?=$pubdate_."&nbsp;&nbsp;".$hour_?></font>
	   <?}if($display_allnews__==1 || $display_allnews__==3){?>
   	   <br><a class="contlink1_" href="<?=$all_news_res[0]['url']?>" target="_new"><?=$feed_desc?></a>
	   <?}?>
   </td>
</tr>
<tr><td height="5"></tr>
<?
}

   if($all_new_news_res[0]['newsitem_id']!="")
       {
           $all_news_id_=$all_new_news_res[0]['newsitem_id'];
           $hour_=str_replace(":","h",$all_new_news_res[0]['hour']);
           $date=explode("-",$all_new_news_res[0]['pubdate']);
           $date=$date[2]."/".$date[1]."/".$date[0];


  		   $yesterday = strftime ("%e/%m/%Y", strtotime("-1 day"));
  		   $yday=explode("/",$yesterday);
		/*
			 if(substr($yday[1],0,1)==0)
				$ymon=str_replace("0","",$yday[1]);
			 else
		*/
				$ymon=$yday[1];

		     if(strlen(trim($yday[0]))==1)
			   $yday[0] ="0".trim($yday[0]);

  		  $yesterday=trim($yday[0])."/".$ymon."/".$yday[2];
  		  $today=date('d/m/Y');

			if($date==$today)
			 $pubdate_=$today_;
			elseif($date == $yesterday)
			 $pubdate_=$yesterday_;
			else
			 $pubdate_=$date;

    	  $title_=str_replace("||","'",$all_new_news_res[0]['title']);
  		  $rep_title=$title_;
  		  $rep_title=str_replace("é","é",$rep_title);
  		  $rep_title=str_replace("’","’",$rep_title);
  		  $rep_title=str_replace("è","è",$rep_title);
  		  $rep_title=str_replace("Ã","à",$rep_title);
  		  $rep_title=str_replace("àª","ê",$rep_title);
  		  $rep_title=str_replace("‘","‘",$rep_title);
  		  $rep_title=str_replace("à»","û",$rep_title);
  		  $title_=$rep_title;

       	  $allnews_desc=html_entity_decode(trim(strip_tags($all_new_news_res[0]['introtext'])));
  		  $allnews_desc=str_replace("||","'",$allnews_desc);
		  $allnewsrep_desc=$allnews_desc;
		  $allnewsrep_desc=str_replace("é","é",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("’","’",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("è","è",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("Ã","à",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("àª","ê",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("‘","‘",$allnewsrep_desc);
		  $allnewsrep_desc=str_replace("à»",û,$allnewsrep_desc);
		  $allnews_desc=$allnewsrep_desc;

		if(strlen($allnews_desc)>$length__){
		   $allnews_desc=substr($allnews_desc,0,$length__);
		   $allnews_ex_intro=strrchr(trim($allnews_desc)," ");

		   if($ex_intro!=""){
			  $ex_new_str=explode($allnews_ex_intro,$allnews_desc);
			  $allnews_desc=$allnews_ex_new_str[0]."...";
			}
		 }else{
		   $allnews_desc=$allnews_desc;
		}

  ?>
  <tr>
  	 <td valign="Top"><a href="view_fodarticle.php?id=<?=$all_news_id_?>&lang=<?=$lang?>" class="contblue2"><?=$title_?></a>
	   <?if($display_allnews__==1 || $display_allnews__==2){?>
  		 <font class="contgrey2"><?=$pubdate_."&nbsp;&nbsp;".$hour_?></font>
     <?}if($display_allnews__==1 || $display_allnews__==3){?>
	  <br><a class="contlink1_" href="view_fodarticle.php?id=<?=$all_news_id_?>&lang=<?=$lang?>"><?=$allnews_desc?></a>
	 <?}?>
     </td>
  </tr>
  <tr><td height="5"></tr>

  <?

  }
}
 if(count($xml_cnt_)>0)
 {
 ?>
<tr><td valign="bottom" align="right" colspan="3">&nbsp;</td></tr>
<?}else{
    if($comp_id=="")
	   $all_msg=$no_news_avail;
?>
<tr><td class="msg" width="95%" valign="Top" align="center"><?=$all_msg?></td></tr>
<?}?>
</table>
Return current item: News Manager - RSS aggregator