phpcms二次开发:phpcms的rss问题

2013-05-25 06:50 阅读 539 次 评论关闭

phpcms中的rss功能有一些小问题,一是生成的链接过长,二是不能生成全站rss,只能是栏目级别

注:在自己直接输出的代码中发现如果标题内容含有特殊字符(必如:"&"符号)会出现生成的rss不能解析错误

1,如果只是解决链接太长,大部分订阅网站不能正常订阅问题,使用url规则进行转换应该就就可以了(没有测试过)

 

2,

<?php 
include "db_config.php";
header("Content-type:text/xml;charset=gbk");

$rss="<?xml version=\"1.0\" encoding=\"gbk\"?>\r\n";
$rss.="<rss version=\"2.0\"  xmlns:atom=\"http://www.w3.org/2005/Atom\" >\r\n";
$rss .="<channel>\r\n"; 
$rss.="<title>xxxx社会经济研究所</title>\r\n";
$rss.="<link>http://www.zhuanxing.cn/</link>\r\n";
$rss.="<description><![CDATA[xxxx社会经济研究所全站文章订阅 ]]></description>\r\n";
$rss.="<language>GBK</language>\r\n";
$rss.="<webMaster>http://xxx.cn</webMaster> \r\n";
$rss.="<copyright>new sitexxxx</copyright> \r\n";
$rss.="<pubDate>".date("Y-m-d H:i:s")."</pubDate> \r\n\r\n";



echo $rss;

 
$db_sql="select id,title,url,description,thumb,aut,inputtime from `v9_news` where islink=0  order by id desc limit 50 ";
$db_result=mysqli_query($db_conn,$db_sql) or die("Err in query:".mysqli_error());


if (mysqli_num_rows($db_result)>0)
{    
   
    while($r=mysqli_fetch_assoc($db_result))
    {    
        echo "\r\n<item>\r\n";

    echo "<title>".htmlspecialchars($r['title'])."</title>\r\n";    
    echo "<link>"."<![CDATA[".htmlspecialchars($r['url'])."]]>"."</link>\r\n";    
    echo "<description>\r\n";
    if($r['thumb']!=""){
    echo "<![CDATA[<img src=".$r['thumb']." border='0'  /><br />".htmlspecialchars($r['description'])."]]>";
    }else{
        echo "<![CDATA[".htmlspecialchars($r['description'])."]]>";
    }
    
    echo"</description>\r\n";    

    echo "<pubDate>".date('Y-m-d',$r['inputtime'])."</pubDate>\r\n";    
    echo "<guid><![CDATA[".$r['url']."]]></guid>\r\n";
    echo "<author>".$r['aut']."</author>\r\n";    
    echo "</item>\r\n";        

    }
    
}
else
{    
    echo "no recoder";
}

mysqli_free_result($db_result);//释放结果集
mysqli_close($db_conn);//释放连接

$foot="\r\n\r\n</channel></rss>";    
echo $foot;


?>

 

其他栏目页可以和上面的页面合并成一个文件

<?php 
include "db_config.php";
header("Content-type:text/xml;charset=gbk");

$cate_catname;
$cate_image;
$cate_url;
$cate_description;
$ccatid;

$db_sqlx="select * from `v9_category` where catid=".intval($_GET["rssid"]);
$db_x=mysqli_query($db_conn,$db_sqlx) or die ("err in query 1:");

if ($db_catid=mysqli_fetch_assoc($db_x))
{ 
$ccatid=$db_catid['arrchildid'];
$cate_catname=$db_catid['catname'];
$cate_image=$db_catid['image'];
$cate_url=$db_catid['url'];
$cate_description=$db_catid['description'];
}

mysqli_free_result($db_x);//释放结果集

$rss="<?xml version=\"1.0\" encoding=\"gbk\"?>\r\n";
$rss.= "<rss version=\"2.0\"  xmlns:atom=\"http://www.w3.org/2005/Atom\" >\r\n";
$rss .= "<channel>\r\n"; 
$rss.="<title>".$cate_catname."</title>";
$rss.=" <link>http://xxx.cn/".$cate_url."</link>";
$rss.=" <description>".$cate_description."</description>";
$rss.="<image><url><![CDATA[".$cate_image." ]]></url></image>";
$rss.="  <language>GBK</language>";
$rss.="<webMaster>http://xxxxxx.cn</webMaster> ";
$rss.=" <copyright>xxxxx</copyright> ";
$rss.=" <pubDate>".date("Y-m-d H:i:s")."</pubDate> ";

echo $rss;


$db_sql="select  id,title,url,description,thumb,aut,inputtime  from `v9_news` where catid in (".$ccatid.") and islink=0  order by id desc limit 30 ";

$db_result=mysqli_query($db_conn,$db_sql) or die("Err in query 2:".$db_sql.mysqli_error());


if (mysqli_num_rows($db_result)>0)
{       
    while($r=mysqli_fetch_assoc($db_result))
    {    
    echo "\r\n<item>\r\n";
    echo "<title>".htmlspecialchars($r['title'])."</title>\r\n";    
    echo "<link>"."<![CDATA[".htmlspecialchars($r['url'])."]]>"."</link>\r\n";    
    echo "<description>\r\n";
    
    if($r['thumb']!=""){
    echo "<![CDATA[<img src=".$r['thumb']." border='0'  /><br />".htmlspecialchars($r['description'])."]]>";
    }else{
        echo "<![CDATA[".htmlspecialchars($r['description'])."]]>";
    }    
    echo"</description>\r\n";

    echo "<pubDate>".date('Y-m-d',$r['inputtime'])."</pubDate>\r\n";    
    echo "<guid><![CDATA[".$r['url']."]]></guid>\r\n";    
    echo "<author>".$r['aut']."</author>\r\n";    
    echo "</item>\r\n";    
    }    
}
else
{    
    echo "no recoder";
}

mysqli_free_result($db_result);//释放结果集

mysqli_close($db_conn);//释放连接

$foot="</channel></rss>";
echo $foot;

?>

如果要同时解决两个问题,我的方法是为此需要重新写这个页面

下面是简单的输出代码来完成,如果有人使用rss来重写,应该更好

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:phpcms二次开发:phpcms的rss问题 | 猎微网

评论已关闭!