⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rss.php

📁 极限网络智能办公系统 - Office Automation 2008 官方100% 源码
💻 PHP
字号:
<?php
 

class myoa_rss
{

	public $file = NULL;
	public $data = NULL;
	public $rss_channel = array( );
	public $currently_writing = "";
	public $main = "";
	public $item_counter = 0;

	public function startElement( $parser, $name, $attrs )
	{
		switch ( $name )
		{
		case "RSS" :
		case "RDF:RDF" :
		case "ITEMS" :
			$this->currently_writing = "";
			return;
		case "CHANNEL" :
			$this->main = "CHANNEL";
			return;
		case "IMAGE" :
			$this->main = "IMAGE";
			$this->rss_channel['IMAGE'] = array( );
			return;
		case "ITEM" :
			$this->main = "ITEMS";
			return;
		}
		$this->currently_writing = $name;
	}

	public function endElement( $parser, $name )
	{
		if ( $name == "IMAGE" )
		{
			$this->main = "CHANNEL";
		}
		$this->currently_writing = "";
		if ( $name == "ITEM" )
		{
			$this->item_counter++;
		}
	}

	public function characterData( $parser, $data )
	{
		$data = iconv( "UTF-8", "GB18030", $data );
		if ( $this->currently_writing != "" )
		{
			switch ( $this->main )
			{
			case "CHANNEL" :
				if ( isset( $this->rss_channel[$this->currently_writing] ) )
				{
					$this->rss_channel[$this->currently_writing] = $data;
				}
				else
				{
					$this->rss_channel[$this->currently_writing] = $data;
				}
				break;
			case "IMAGE" :
				if ( isset( $this->rss_channel[$this->main][$this->currently_writing] ) )
				{
					$this->rss_channel[$this->main][$this->currently_writing] .= $data;
				}
				else
				{
					$this->rss_channel[$this->main][$this->currently_writing] = $data;
				}
				break;
			case "ITEMS" :
				if ( isset( $this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] ) )
				{
					$this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] .= $data;
				}
				else
				{
					$this->rss_channel[$this->main][$this->item_counter][$this->currently_writing] = $data;
				}
			}
		}
	}

	public function myoa_rss( $file = "" )
	{
		$this->file = $file;
		$this->data = "";
		if ( $file != "" )
		{
			$fp = @fopen( $file, "rb" );
			while ( !feof( $fp ) )
			{
				$this->data .= fread( $fp, 4096 );
			}
			fclose( $fp );
		}
	}

	public function parse( $data = "" )
	{
		$this->xml_parser = xml_parser_create( );
		xml_set_object( $this->xml_parser, &$this );
		xml_set_element_handler( $this->xml_parser, "startElement", "endElement" );
		xml_set_character_data_handler( $this->xml_parser, "characterData" );
		if ( $data == "" )
		{
			$data = $this->data;
		}
		if ( substr( $data, 0, 1 ) != "<" )
		{
			$this->data = substr( $data, strpos( $data, "<" ) );
		}
		xml_parse( $this->xml_parser, $data );
		xml_parser_free( $this->xml_parser );
	}

	public function getTitle( )
	{
		return $this->rss_channel['TITLE'];
	}

	public function getContent( $rows_count = 10 )
	{
		if ( isset( $this->rss_channel['ITEMS'] ) && 0 < count( $this->rss_channel['ITEMS'] ) )
		{
			$i = 0;
			for ( ;	$i < count( $this->rss_channel['ITEMS'] );	++$i	)
			{
				if ( $rows_count != 0 && $rows_count <= $i )
				{
					break;
				}
				$itemTitle = strip_tags( $this->rss_channel['ITEMS'][$i]['TITLE'] );
				$itemLink = $this->rss_channel['ITEMS'][$i]['LINK'];
				if ( $this->rss_channel['ITEMS'][$i]['PUBDATE'] != "" )
				{
					$TimeStamp = strtotime( $this->rss_channel['ITEMS'][$i]['PUBDATE'] );
					if ( $TimeStamp != -1 )
					{
						$itemPubDate = " (".date( "Y-m-d H:i", $TimeStamp ).")";
					}
				}
				$OUTPUT_HTML .= "·<a href=\"".$itemLink."\" target=\"_blank\"";
				if ( $rows_count != 0 && 64 < strlen( $itemTitle ) )
				{
					$OUTPUT_HTML .= " title=\"".$itemTitle."\">".csubstr( $itemTitle, 0, 60 )."...";
				}
				else
				{
					$OUTPUT_HTML .= ">".$itemTitle;
				}
				$OUTPUT_HTML .= "</a>".$itemPubDate."<br>";
			}
		}
		return $OUTPUT_HTML;
	}

}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -