Home php教程 php手册 rss2生成类

rss2生成类

Jun 21, 2016 am 09:05 AM
channel gt lt this

rss

  • 1

    php/**//* * @(#)Rss2Gen.inc.php (beta) 2005/2/19 *  * exblog RSS2 生成类,实现了RSS2规范中的大部分内容。 *  * 使用方法请见本类底部(Rss2Gen类使用注释)信息。 * * 本程序为免费程序,源代码使用者可任意更改(请勿用于商业用途),但请保留本版权信息! *  * @author  HexUzHoNG <hexuzhong> * @version beta-2, 2005-03-11 * @since   exBlog-1.3.0 * */ class Rss2Gen {    var $rss_header;  //RSS文档头,存放一个<rss>根元素及其version属性。  var $item;    //  var $items; var $channel_header; //频道的头部信息,存放频道名称、URL、描述、语言、版权等等。 //--------------- 以下元素是可选的频道子元素 --------------// var $channel_language; //频道使用的语言种类,例如en-us、zh-cn等,放便聚集器组织中一语言的站点。 var $channel_copyright; //频道内容的版权声明。 var $channel_managingEditor; //对该频道内容负责的个人的Email地址 var $channel_webMaster;   //对该频道的技术支持负责的个人的Email地址 var $channel_pubDate;   //该频道内容的公布日期 var $channel_lastBuildDate;  //上次频道内容更改的时间 var $channel_category;   //说明频道属于哪一个或多个分类 var $channel_generator = "<generator>exblog RSS2 builder</generator>"; //用于生成该频道的程序 var $channel_docs;   //RSS文件所使用格式的说明文档所在的URL var $channel_cloud;   //允许进程注册为“cloud”,频道更新时通知它 var $channel_ttl;   //ttl 代表存活时间,存活时间是一个数字,表示提要在刷新之前缓冲的分钟数 var $channel_image;   //指定一个能在频道中显示的GIF、JPEG 或PNG 图像 //var $channel_rating;  //关于该频道的 PICS 评价 //var $channel_textInput;  //定义可与频道一起显示的输入框 //var $channel_skipHours;  //告诉聚集器哪些小时的更新可以忽略 //var $channel_skipDays;  //告诉聚集器那一天的更新可以忽略  var $channel;   //整个rss2文档信息,用与生成整个页面。  var $halt_on_error = true;   /**//**    * 构造函数,其参数皆为rss2必须的频道子元素,如果不填,则为默认内容。   *    * @param String $title 频道的名称,频道的title应该和web站点的title尽量一致。   * @param String $link 与该频道关联的web站点的URL。   * @param String $description 对频道的一段简单描述,如介绍频道是做什么的。   * @access public   */  function Rss2Gen() {  $this->fillHeader();  }    /**//**   * 生成RSS文档头,必须以一个<rss>元素作为根元素,其有一个强制属性version,指定当前文档遵守的RSS版本。   * @access private   */  function fillHeader() {   $this->rss_header = "</rss></rss></hexuzhong>

    Copy after login
    <font face="新宋体"><span style="BORDER-BOTTOM: #ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000bb"></span><span style="COLOR: #0000bb">xml</span><span style="COLOR: #0000bb"> </span><span style="COLOR: #0000bb">version</span><span style="COLOR: #007700">=</span><span style="COLOR: #007700">"</span><span style="COLOR: #0000bb">1</span><span style="COLOR: #0000bb">.</span><span style="COLOR: #0000bb">0</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb"> </span><span style="COLOR: #0000bb">encoding</span><span style="COLOR: #0000bb">=</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb">gb2312</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb">?></span></span><br></font>

    1

    rn";   $this->rss_header .= " <rss version="2.0">rn";  }  /**//**  * 设置频道头,其中三个元素为必须的。  * @param String $title 频道的名称,频道的title应该和Web站点的title尽量一致。  * @param String $link 与该频道关联的Web站点或者站点区域的URL。  * @param String $description 对频道的一段简单描述,简要介绍频道是做什么的。  */ function setChannel($title = "exblog", $link = "http://www.exblog.org", $description = "exblog") {  $this->channel_header = "  <title></title>n";   $this->channel_header .= "  <link>".$link."rn";   $this->channel_header .= "  <description></description>rn"; }  function halt($msg) {  if ($this->halt_on_error) {   $this->haltmsg($msg);  }  die("exblog RSS2 exit"); }  function haltmsg($msg) {  sprintf("<b>exblog RSS2 builder ERROR: %s</b><br>rn", $msg); }  /**//**  * 设置该RSS文档的语言,默认为简体中文。  * @access public  */  function setLanguage($lang = "zh_cn") {   $this->channel_language = "  <language>".$lang."</language>rn";   }   /**//**  * 频道内容的版权声明  * @access public  */  function setCopyright($copyright = "exblog") {   $this->channel_copyright = "  <copyright>".$copyright."</copyright>rn";  }   /**//**  * 对该频道内容负责的个人的Email地址  * @access public  */  function setManagingEditor($email = NULL) {   if (empty($email)) {    $this->halt("如果你设置了该频道内容负责的个人的Email地址,请填写她。");   }   $this->channel_managingEditor = "  <managingeditor>".$email."</managingeditor>rn";  }   /**//**  * 对该频道的技术支持负责的个人的Email地址  * @access public  */  function setWebMaster($email = NULL) {   if (empty($email)) {    $this->halt("如果你设置了该频道的技术支持负责的个人的Email地址,请填写她。 :)");   }   $this->channel_webMaster = "  <webmaster>".$email."</webmaster>rn";  }  /**//**  * 该频道内容的公布日期。  * @access public  */  function setPubDate($date = NULL) {   if (empty($date)) {   $date = date("Y/m/d");    $this->channel_pubDate = "  <pubdate>".$date."</pubdate>rn";   }   $this->channel_pubDate = "  <pubdate>".$date."</pubdate>rn";  }   /**//**  * 上次频道内容更改的时间  * @access public  */  function setLastBuildDate($date = NULL) {  if (empty($date)) {   $date = date("Y/m/d");     $this->channel_lastBuildDate = "  <lastbuilddate>".$date."</lastbuilddate>rn";   }   $this->channel_lastBuildDate = "  <lastbuilddate>".$date."</lastbuilddate>rn";  } /**//**  * 说明频道属于哪一个或多个分类  * @access public  */  function setCategory($category) {   $this->channel_category = "  <category>".$category."</category>rn";  }  /**//**  * RSS文件所使用格式的说明文档所在的URL  * @access public  */  function setDocs($url) {   $this->channel_docs = "  <docs>".$url."</docs>rn";  }  /**//**  * ttl 代表存活时间,存活时间是一个数字,表示提要在刷新之前缓冲的分钟数  * @access public  */  function setTtl($minute) {   $this->channel_ttl = "  <ttl>".$minute."</ttl>rn";  }  /**//**  * 指定一个能在频道中显示的GIF、JPEG 或PNG 图像  *  * @param String $url 必需,是表示该频道的 GIF、JPEG 或 PNG 图像的URL  * @param String $title 必需,是图象的描述。当频道以 HTML 呈现时,用作 HTML <image> 标签的 ALT 属性。  * @param String $link 必需,是站点的 URL。如果频道以 HTML 呈现,该图像作为到这个站点的链接。  * @param Integer $width 表示图象的像素宽,必须和 $height 一同设置,否则不会显示此属性。  * @param Integer $height 表示图象的像素高,必须和 $width 一同设置,否则不会显示此属性。  * @param String $description 围绕着该图像形成的链接元素的 title 属性。  *  * @access public  */  function setChannelImage($url, $title, $link, $width = NULL, $height = NULL, $description = NULL) {   if (!isset($url))    $this->halt("如果你要设置图片,该图像地址属性必须填写。");   if (!isset($title))    $this->halt("如果你要设置图片,该图像描述属性必须填写。");   if (!isset($link))    $this->halt("如果你要设置图片,该图像链接属性必须填写。这个URL一般和图像地址属性相同");   $this->channel_image = "  <image>rn";   $this->channel_image .= "   <url>".$url."</url>rn";   $this->channel_image .= "   <title></title>rn";   $this->channel_image .= "   <link>".$link."rn";   //如果设置了图像宽、高则添加此属性。   if (!empty($width) && !empty($height)) {    $this->channel_image .= "   <width>".$width."</width>rn";    $this->channel_image .= "   <height>".$height."</height>rn";   }   if (!empty($description))    $this->channel_image .= "   <description></description>rn";   $this->channel_image .= "</image>rn";  }    /**//**   * 添加一条item到channel中,虽然item的子元素都是可选的,但至少要存在一个title或description  *  * @param String $title 项(item)的标题  * @param String $description 项(item)的大纲  * @param String $link 项(item)的URL  * @param String $author 项(item)作者的Email 地址  * @param String $category 包括项(item)的一个或多个分类  * @param String $comments 关于项(item)的注释页的URL  * @param String $enclosure 支持和该项(item)有关的媒体对象  * @param String $guid 唯一与该项(item)联系在一起的永久性链接  * @param String $pubDate 该项(item)是什么时候发布的  * @param String $Source 该项(item)来自哪个RSS 频道,当把项(item)聚合在一起时非常有用  *  * @access public   */  function addItem($title = NULL, $description = NULL, $link = NULL, $author = NULL, $category = NULL, $comments = NULL, $enclosure = NULL, $guid = NULL, $pubDate = NULL, $source = NULL) {   //判断是否至少添加了title或description   if (empty($title) && empty($description)) {   $this->halt("item:请至少设置title或description属性。");  }  else {    $this->item = "  <item>rn";    if (!empty($title))     $this->item .= "   <title></title>rn";    if (!empty($link))     $this->item .= "   <link>".$link."rn";    if (!empty($description))     $this->item .= "   <description></description>rn";    if (!empty($author))     $this->item .= "   <author></author>rn";    if (!empty($category))     $this->item .= "  <category></category>rn";    if (!empty($comments))     $this->item .= "   <comments></comments>rn";    if (!empty($enclosure))     $this->item .= "   <enclosure></enclosure>rn";     if (!empty($guid))     $this->item .= "   <guid>".$guid."</guid>rn";    if (!empty($pubDate))     $this->item .= "   <pubdate>".$pubDate."</pubdate>rn";    if (!empty($source))     $this->item .= "   <source></source>rn";    $this->item .= "</item>rn";   }   $this->items .= $this->item;  }   /**//**  * 输出 rss2 文档  */  function builder() {  $this->stuff();  header("Content-type:application/xml");  print $this->channel;  }  /**//**  * 兼容老版本rss生成方法,去掉了写文件功能。  *  */ function buildRssFeed($param = NULL) {  $this->builder(); } /**//**  * 合成整个RSS2文档  *  */ function stuff() {  $this->channel = $this->rss_header;  $this->channel .= $this->channel_header;  if (isset($this->channel_language))   $this->channel .= $this->channel_language;  if (isset($this->channel_copyright))   $this->channel .= $this->channel_copyright;  if (isset($this->channel_managingEditor))   $this->channel .= $this->channel_managingEditor;  if (isset($this->channel_webMaster))   $this->channel .= $this->channel_webMaster;  if (isset($this->channel_pubDate))   $this->channel .= $this->channel_pubDate;  if (isset($this->channel_lastBuildDate))   $this->channel .= $this->channel_lastBuildDate;  if (isset($this->channel_category))   $this->channel .= $this->channel_category;  if (isset($this->channel_docs))   $this->channel .= $this->channel_docs;  if (isset($this->channel_cloud))   $this->channel .= $this->channel_cloud;  if (isset($this->channel_ttl))   $this->channel .= $this->channel_ttl;  if (isset($this->channel_image))   $this->channel .= $this->channel_image;  $this->channel .= $this->channel_generator;  $this->channel .= $this->items;  $this->channel .= "</image></rss>rn"; } } /**//******************************* Rss2Gen 类使用注释 *******************/ /**//* $rss2gen = new Rss2Gen(); $rss2gen->setChannel("exblog222rss", "http://elliott.fengling.net", "elliott rss2gen"); //以下部分为可添加信息 //$rss2gen->setLanguage("zh-cn"); //$rss2gen->setCopyright("exblog @"); //$rss2gen->setManagingEditor("elliott_hee@163.com"); //$rss2gen->setWebMaster("elliott@yeah.net"); //$rss2gen->setPubDate(); //$rss2gen->setLastBuildDate(); //$rss2gen->setCategory("none"); //$rss2gen->setDocs("http://www.exblog.org/rss_docs.html"); //$rss2gen->setTtl(600); //$rss2gen->setChannelImage("/XrssFile/2006-9/24/200692413947513.gif", "demo~~ :)", "http://www.exblog.org"); //------------------------ //---添加一条记录到rss文档中,至少需要一个参数,title或description $rss2gen->addItem("item1", "item1's description", "http://www.exblog.org/?play=1",        "elliott", "默认分类", "描述呀描述。", "支持和该项(item)有关的媒体对象",       "唯一与该项(item)联系在一起的永久性链接", "2005-03-12",       "该项(item)来自哪个RSS 频道,当把项(item)聚合在一起时非常有用"); $rss2gen->addItem("item2", "item2's description"); $rss2gen->addItem("item3"); $rss2gen->builder(); //兼容老版本中方法 //$rss2gen->buildRssFeed(); */

    Copy after login


  • Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

    Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

    Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

    Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

    How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

    Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

    php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

    php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

    Let's talk about why Vue2 can access properties in various options through this Let's talk about why Vue2 can access properties in various options through this Dec 08, 2022 pm 08:22 PM

    This article will help you interpret the vue source code and introduce why you can use this to access properties in various options in Vue2. I hope it will be helpful to everyone!

    An article that understands this point and catches up with 70% of front-end people An article that understands this point and catches up with 70% of front-end people Sep 06, 2022 pm 05:03 PM

    A colleague got stuck due to a bug pointed by this. Vue2’s this pointing problem caused an arrow function to be used, resulting in the inability to get the corresponding props. He didn't know it when I introduced it to him, and then I deliberately looked at the front-end communication group. So far, at least 70% of front-end programmers still don't understand it. Today I will share with you this link. If everything is wrong If you haven’t learned it yet, please give me a big mouth.

    What does channel mean in Go language? What does channel mean in Go language? Dec 14, 2023 pm 02:21 PM

    Channel in Go language is a mechanism for communication and data synchronization between coroutines. Can be thought of as a special data type, similar to a queue or pipe, used to transfer data between different coroutines. Channel provides two main operations: send and receive. Both send and receive operations in a channel are blocking, which means that if no sender or receiver is ready, the operation will be blocked until a coroutine is ready to perform the corresponding operation, etc.

    How does golang function communicate with goroutine through channel? How does golang function communicate with goroutine through channel? May 01, 2024 pm 09:42 PM

    Go language uses channels and goroutines to communicate. After creating the channel, the goroutine can pass

    See all articles