📄 rss.class.php
字号:
/**#@-*/
/**#@+
* @access public
*/
/**
* Checks if a given string is a valid iso-language-code
*
* @desc Checks if a given string is a valid iso-language-code
* @param string $code String that should validated
* @return boolean $isvalid If string is valid or not
* @static
*/
function isValidLanguageCode($code = '') {
return (boolean) ((preg_match('(^([a-zA-Z]{2})$)',$code) > 0) ? TRUE : FALSE);
} // end function
/**
* Returns $encoding variable
*
* @desc Returns $encoding variable
* @return string $encoding
* @see $image_link
*/
function getEncoding() {
return (string) $this->encoding;
} // end function
/**
* Returns $about variable
*
* @desc Returns $about variable
* @return string $about
* @see $about
*/
function getAbout() {
return (string) $this->about;
} // end function
/**
* Returns $title variable
*
* @desc Returns $title variable
* @return string $title
* @see $title
*/
function getTitle() {
return (string) $this->title;
} // end function
/**
* Returns $description variable
*
* @desc Returns $description variable
* @return string $description
* @see $description
*/
function getDescription() {
return (string) $this->description;
} // end function
/**
* Returns $publisher variable
*
* @desc Returns $publisher variable
* @return string $publisher
* @see $publisher
*/
function getPublisher() {
return (string) $this->publisher;
} // end function
/**
* Returns $creator variable
*
* @desc Returns $creator variable
* @return string $creator
* @see $creator
*/
function getCreator() {
return (string) $this->creator;
} // end function
/**
* Returns $date variable
*
* @desc Returns $date variable
* @return string $date
* @see $date
*/
function getDate() {
return (string) $this->date;
} // end function
/**
* Returns $language variable
*
* @desc Returns $language variable
* @return string $language
* @see $language
*/
function getLanguage() {
return (string) $this->language;
} // end function
/**
* Returns $rights variable
*
* @desc Returns $rights variable
* @return string $rights
* @see $rights
*/
function getRights() {
return (string) $this->rights;
} // end function
/**
* Returns $coverage variable
*
* @desc Returns $coverage variable
* @return string $coverage
* @see $coverage
*/
function getCoverage() {
return (string) $this->coverage;
} // end function
/**
* Returns $contributor variable
*
* @desc Returns $contributor variable
* @return string $contributor
* @see $contributor
*/
function getContributor() {
return (string) $this->contributor;
} // end function
/**
* Returns $image_link variable
*
* @desc Returns $image_link variable
* @return string $image_link
* @see $image_link
*/
function getImageLink() {
return (string) $this->image_link;
} // end function
/**
* Returns $period variable
*
* @desc Returns $period variable
* @return string $period
* @see $period
*/
function getPeriod() {
return (string) $this->period;
} // end function
/**
* Returns $frequency variable
*
* @desc Returns $frequency variable
* @return string $frequency
* @see $frequency
*/
function getFrequency() {
return (int) $this->frequency;
} // end function
/**
* Returns $base variable
*
* @desc Returns $base variable
* @return string $base
* @see $base
*/
function getBase() {
return (string) $this->base;
} // end function
/**
* Returns $category variable
*
* @desc Returns $category variable
* @return string $category
* @see $category
* @since 1.001 - 2003-05-30
*/
function getCategory() {
return (string) $this->category;
} // end function
/**
* Returns $cache variable
*
* @desc Returns $cache variable
* @return int $cache
* @see $cache
* @since 1.001 - 2003-05-30
*/
function getCache() {
return (int) $this->cache;
} // end function
/**
* Adds another rss item to the object
*
* @desc Adds another rss item to the object
* @param string $about URL
* @param string $title
* @param string $link URL
* @param string $description (optional)
* @param string $subject some sort of category (optional dc value - only shows up if DC data has been set before)
* @param string $date format: 2003-05-29T00:03:07+0200 (optional dc value - only shows up if DC data has been set before)
* @param string $author some sort of category author of item
* @param string $comments url to comment page rss 2.0 value
* @param string $image optional mod_im value for dispaying a different pic for every item
* @return void
* @see $items
* @uses RSSItem
*/
function addItem($about = '',
$title = '',
$link = '',
$description = '',
$subject = '',
$date = '',
$author = '',
$comments = '',
$image = '') {
$item = new RSSItem($about,
$title,
$link,
$description,
$subject,
$date,
$author,
$comments,
$image);
$this->items[] = $item;
} // end function
/**
* Deletes a rss item from the array
*
* @desc Deletes a rss item from the array
* @param int $id id of the element in the $items array
* @return boolean true if item was deleted
* @see $items
*/
function deleteItem($id = -1) {
if (array_key_exists($id, $this->items)) {
unset($this->items[$id]);
return (boolean) TRUE;
} else {
return (boolean) FALSE;
} // end if
} // end function
/**
* Returns an array with all the keys of the $items array
*
* @desc Returns an array with all the keys of the $items array
* @return array array with all the keys of the $items array
* @see $items
*/
function getItemList() {
return (array) array_keys($this->items);
} // end function
/**
* Returns the $items array
*
* @desc Returns the $items array
* @return array $items
*/
function getItems() {
return (array) $this->items;
} // end function
/**
* Returns a single rss item by ID
*
* @desc Returns a single rss item by ID
* @param int $id id of the element in the $items array
* @return mixed RSSItem or FALSE
* @see RSSItem
*/
function getItem($id = -1) {
if (array_key_exists($id, $this->items)) {
return (object) $this->items[$id];
} else {
return (boolean) FALSE;
} // end if
} // end function
/**#@-*/
/**#@+
* @return void
* @access private
*/
/**
* creates the output based on the 0.91 rss version
*
* @desc creates the output based on the 0.91 rss version
* @see $output
*/
function createOutputV090() {
// not implemented
$this->createOutputV100();
} // end function
/**
* creates the output based on the 0.91 rss version
*
* @desc creates the output based on the 0.91 rss version
* @see $output
* @since 1.001 - 2003-05-30
*/
function createOutputV091() {
$this->output = (string) '<!DOCTYPE rss SYSTEM "http://my.netscape.com/publish/formats/rss-0.91.dtd">' . "\n";
$this->output .= (string) '<rss version="0.91">' . "\n";
$this->output .= (string) '<channel>' . "\n";
if (strlen($this->rights) > 0) {
$this->output .= (string) '<copyright>' . $this->rights . '</copyright>' . "\n";
} // end if
if (strlen($this->date) > 0) {
$this->output .= (string) '<pubDate>' .$this->date . '</pubDate>' . "\n";
$this->output .= (string) '<lastBuildDate>' .$this->date . '</lastBuildDate>' . "\n";
} // end if
if (strlen($this->about) > 0) {
$this->output .= (string) '<docs>' . $this->about . '</docs>' . "\n";
} // end if
if (strlen($this->description) > 0) {
$this->output .= (string) '<description>' . $this->description . '</description>' . "\n";
} // end if
if (strlen($this->about) > 0) {
$this->output .= (string) '<link>' . $this->about . '</link>' . "\n";
} // end if
if (strlen($this->title) > 0) {
$this->output .= (string) '<title>' . $this->title . '</title>' . "\n";
} // end if
if (strlen($this->image_link) > 0) {
$this->output .= (string) '<image>' . "\n";
$this->output .= (string) '<title>' . $this->title . '</title>' . "\n";
$this->output .= (string) '<url>' . $this->image_link . '</url>' . "\n";
$this->output .= (string) '<link>' . $this->about . '</link>' . "\n";
if (strlen($this->description) > 0) {
$this->output .= (string) '<description>' . $this->description . '</description>' . "\n";
} // end if
$this->output .= (string) '</image>' . "\n";
} // end if
if (strlen($this->publisher) > 0) {
$this->output .= (string) '<managingEditor>' . $this->publisher . '</managingEditor>' . "\n";
} // end if
if (strlen($this->creator) > 0) {
$this->output .= (string) '<webMaster>' . $this->creator . '</webMaster>' . "\n";
} // end if
if (strlen($this->language) > 0) {
$this->output .= (string) '<language>' . $this->language . '</language>' . "\n";
} // end if
if (count($this->getItemList()) > 0) {
foreach ($this->getItemList() as $id) {
$item =& $this->items[$id];
if (strlen($item->getTitle()) > 0 && strlen($item->getLink()) > 0) {
$this->output .= (string) '<item>' . "\n";
$this->output .= (string) '<title>' . $item->getTitle() . '</title>' . "\n";
$this->output .= (string) '<link>' . $item->getLink() . '</link>' . "\n";
if (strlen($item->getDescription()) > 0) {
$this->output .= (string) '<description>' . $item->getDescription() . '</description>' . "\n";
} // end if
$this->output .= (string) '</item>' . "\n";
} // end if
} // end foreach
} // end if
$this->output .= (string) '</channel>' . "\n";
$this->output .= (string) '</rss>' . "\n";
} // end function
/**
* creates the output based on the 1.0 rss version
*
* @desc creates the output based on the 1.0 rss version
* @see $output
*/
function createOutputV100() {
$this->output = (string) '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:im="http://purl.org/rss/1.0/item-images/" ';
if ($this->use_dc_data === TRUE) {
$this->output .= (string) 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
} // end if
if ($this->use_sy_data === TRUE) {
$this->output .= (string) 'xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" ';
} // end if
$this->output .= (string) 'xmlns="http://purl.org/rss/1.0/">' . "\n";
if (strlen($this->about) > 0) {
$this->output .= (string) '<channel rdf:about="' . $this->about . '">' . "\n";
} else {
$this->output .= (string) '<channel>' . "\n";
} // end if
if (strlen($this->title) > 0) {
$this->output .= (string) '<title>' . $this->title . '</title>' . "\n";
} // end if
if (strlen($this->about) > 0) {
$this->output .= (string) '<link>' . $this->about . '</link>' . "\n";
} // end if
if (strlen($this->description) > 0) {
$this->output .= (string) '<description>' . $this->description . '</description>' . "\n";
} // end if
// additional dc data
if (strlen($this->publisher) > 0) {
$this->output .= (string) '<dc:publisher>' . $this->publisher . '</dc:publisher>' . "\n";
} // end if
if (strlen($this->creator) > 0) {
$this->output .= (string) '<dc:creator>' . $this->creator . '</dc:creator>' . "\n";
} // end if
if (strlen($this->date) > 0) {
$this->output .= (string) '<dc:date>' .$this->date . '</dc:date>' . "\n";
} // end if
if (strlen($this->language) > 0) {
$this->output .= (string) '<dc:language>' . $this->language . '</dc:language>' . "\n";
} // end if
if (strlen($this->rights) > 0) {
$this->output .= (string) '<dc:rights>' . $this->rights . '</dc:rights>' . "\n";
} // end if
if (strlen($this->coverage) > 0) {
$this->output .= (string) '<dc:coverage>' . $this->coverage . '</dc:coverage>' . "\n";
} // end if
if (strlen($this->contributor) > 0) {
$this->output .= (string) '<dc:contributor>' . $this->contributor . '</dc:contributor>' . "\n";
} // end if
// additional SY data
if (strlen($this->period) > 0) {
$this->output .= (string) '<sy:updatePeriod>' . $this->period . '</sy:updatePeriod>' . "\n";
} // end if
if (strlen($this->frequency) > 0) {
$this->output .= (string) '<sy:updateFrequency>' . $this->frequency . '</sy:updateFrequency>' . "\n";
} // end if
if (strlen($this->base) > 0) {
$this->output .= (string) '<sy:updateBase>' . $this->base . '</sy:updateBase>' . "\n";
} // end if
if (strlen($this->image_link) > 0) {
$this->output .= (string) '<image rdf:about="' . $this->image_link . '">' . "\n";
$this->output .= (string) '<title>' . $this->title . '</title>' . "\n";
$this->output .= (string) '<url>' . $this->image_link . '</url>' . "\n";
$this->output .= (string) '<link>' . $this->about . '</link>' . "\n";
if (strlen($this->description) > 0) {
$this->output .= (string) '<description>' . $this->description . '</description>' . "\n";
} // end if
$this->output .= (string) '</image>' . "\n";
} // end if
if (count($this->getItemList()) > 0) {
$this->output .= (string) '<items><rdf:Seq>' . "\n";
foreach ($this->getItemList() as $id) {
$item =& $this->items[$id];
if (strlen($item->getAbout()) > 0) {
$this->output .= (string) ' <rdf:li resource="' . $item->getAbout() . '" />' . "\n";
} // end if
} // end foreach
$this->output .= (string) '</rdf:Seq></items>' . "\n";
} // end if
$this->output .= (string) '</channel>' . "\n";
if (count($this->getItemList()) > 0) {
foreach ($this->getItemList() as $id) {
$item =& $this->items[$id];
if (strlen($item->getTitle()) > 0 && strlen($item->getLink()) > 0) {
if (strlen($item->getAbout()) > 0) {
$this->output .= (string) '<item rdf:about="' . $item->getAbout() . '">' . "\n";
} else {
$this->output .= (string) '<item>' . "\n";
} // end if
$this->output .= (string) '<title>' . $item->getTitle() . '</title>' . "\n";
$this->output .= (string) '<link>' . $item->getLink() . '</link>' . "\n";
if (strlen($item->getDescription()) > 0) {
$this->output .= (string) '<description>' . $item->getDescription() . '</description>' . "\n";
} // end if
if ($this->use_dc_data === TRUE && strlen($item->getSubject()) > 0) {
$this->output .= (string) '<dc:subject>' . $item->getSubject() . '</dc:subject>' . "\n";
} // end if
if ($this->use_dc_data === TRUE && strlen($item->getDate()) > 0) {
$this->output .= (string) '<dc:date>' . $item->getDate() . '</dc:date>' . "\n";
} // end if
if (strlen($item->getImage()) > 0) {
$this->output .= (string) '<im:image>' . $item->getImage() . '</im:image>' . "\n";
} // end if
$this->output .= (string) '</item>' . "\n";
} // end if
} // end foreach
} // end if
$this->output .= (string) '</rdf:RDF>';
} // end function
/**
* creates the output based on the 2.0 rss draft
*
* @desc creates the output based on the 0.91 rss draft
* @see $output
* @since 1.001 - 2003-05-30
*/
function createOutputV200() {
$this->output = (string) '<rss version="2.0" xmlns:im="http://purl.org/rss/1.0/item-images/" ';
if ($this->use_dc_data === TRUE) {
$this->output .= (string) 'xmlns:dc="http://purl.org/dc/elements/1.1/" ';
} // end if
if ($this->use_sy_data === TRUE) {
$this->output .= (string) 'xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" ';
} // end if
$this->output .= (string) '>' . "\n";
$this->output .= (string) '<channel>' . "\n";
if (strlen($this->rights) > 0) {
$this->output .= (string) '<copyright>' . $this->rights . '</copyright>' . "\n";
} // end if
if (strlen($this->date) > 0) {
$this->output .= (string) '<pubDate>' .$this->date . '</pubDate>' . "\n";
$this->output .= (string) '<lastBuildDate>' .$this->date . '</lastBuildDate>' . "\n";
} // end if
if (strlen($this->about) > 0) {
$this->output .= (string) '<docs>' . $this->about . '</docs>' . "\n";
} // end if
if (strlen($this->description) > 0) {
$this->output .= (string) '<description>' . $this->description . '</description>' . "\n";
} // end if
if (strlen($this->about) > 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -