[Valid RSS] class rss_feed extends base { var $xmlns = array(); var $encoding = "UTF-8"; var $content_type = "text/xml"; var $version = "2.0"; var $addAtomSelfLink = true; var $stylesheets = array(); var $title = ""; var $link = ""; var $description = ""; var $language = "en-us"; var $copyright = false; var $managingEditor = false; var $webMaster = false; var $pubDate = false; var $lastBuildDate = false; var $category = false; var $generator = "RSS Feed Generator"; var $docs = false; var $cloud = false; var $ttl = 1440; var $image = false; var $textInput = false; var $skipHours = false; var $skipDays = false; var $xElements = array(); var $item = array(); var $description_out = true; var $description_out_max = 0; var $rssFeedContent = false; var $rssFeedTimeCreated = false; var $rssFeedCahcheFlag = true; var $rssFeedCahcheFileName = false; var $rssFeedCahcheFrom = false; function rss_feed($xmlns = array()) { $this->rss_feed_xmlns($xmlns); } function rss_feed_xmlns($xmlns = "") { if (is_array($xmlns)) { foreach ($xmlns as $i => $v) { $this->xmlns[] = $xmlns[$i]; } } elseif (is_string($xmlns)) { $this->xmlns[] = $xmlns; } } function rss_feed_style($href) { $this->stylesheets[] = $href; } function rss_feed_encoding($encoding) { $this->encoding = $encoding; } function rss_feed_content_type($content_type) { $this->content_type = $content_type; } function rss_feed_set($name, $value) { switch ($name) { case 'title': $this->title = $value; break; case 'link': $this->link = $value; break; case 'description': $this->description = $value; break; case 'language': $this->language = $value; break; case 'copyright': $this->copyright = $value; break; case 'managingEditor': $this->managingEditor = $value; break; case 'webMaster': $this->webMaster = $value; break; case 'pubDate': $this->pubDate = $value; break; case 'lastBuildDate': $this->lastBuildDate = $value; break; // category $this->rss_feed_category case 'generator': $this->generator = $value; break; case 'docs': $this->docs = $value; break; // cloud $this->rss_feed_cloud case 'ttl': $this->ttl = $value; break; // image $this->rss_feed_image // textInput $this->rss_feed_textInput case 'skipHours': $this->skipHours = explode(',', $value); break; case 'skipDays': $this->skipDays = explode(',', $value); break; } return; } function rss_feed_category($name, $domain=false) { $this->category['name'] = $name; $this->category['domain'] = $domain; } function rss_feed_cloud($domain, $port, $path, $registerProcedure, $protocol) { $this->cloud['domain'] = $domain; $this->cloud['port'] = $port; $this->cloud['path'] = $path; $this->cloud['registerProcedure'] = $registerProcedure; $this->cloud['protocol'] = $protocol; } function rss_feed_image($title, $link, $url, $width=0, $height=0, $description=false) { $this->image['title'] = $title; $this->image['link'] = $link; $this->image['url'] = $url; $this->width['width'] = $width; $this->width['height'] = $height; $this->width['description'] = $description; } function rss_feed_textInput($title, $link, $description, $name) { $this->textInput['title'] = $title; $this->textInput['link'] = $link; $this->textInput['description'] = $description; $this->textInput['name'] = $name; } function rss_feed_description_set($out, $max) { $this->description_out = $out; $this->description_out_max = $max; } function rss_feed_item($title, $link, $guid, $pubDate = false, $description = false, $enclosure = false, $comments = false, $author = false, $category = false, $source=false, $ext_tags = array()) { $this->item['title'][] = $title; $this->item['link'][] = $link; $this->item['guid'][] = $guid; $this->item['pubDate'][] = $pubDate; $this->item['description'][] = $description; $this->item['enclosure'][] = $enclosure; $this->item['comments'][] = $comments; $this->item['author'][] = $author; $this->item['category'][] = $category; $this->item['source'][] = $source; $this->item['ext_tags'][] = $ext_tags; } function rss_feed_content() { $feedContent = 'encoding . '"?'.'>' . "\n"; foreach($this->stylesheets as $stylesheet) { if(substr($stylesheet, -3) == 'xsl') { $feedContent .= '' . "\n"; } else { $feedContent .= '' . "\n"; } } if (sizeof($this->xmlns) > 0) { $xmlns = "\n" . implode("\n", $this->xmlns); } else { $xmlns = ""; } if($this->addAtomSelfLink == true) { $xmlns .= "\n" . 'xmlns:atom="http://www.w3.org/2005/Atom"'; } $feedContent .= '' . "\n"; $feedContent .= '' . "\n" . ' ' . "\n" . ' ' . $this->_clear_string($this->title) . '' . "\n" . ' ' . $this->_clear_url($this->link) . '' . "\n" . ' ' . $this->_clear_string($this->description) . '' . "\n"; if($this->addAtomSelfLink == true) { $feedContent .= ' ' . "\n"; } if ($this->language) $feedContent .= ' ' . $this->language . '' . "\n"; if ($this->copyright) $feedContent .= ' ' . $this->_clear_string($this->copyright) . '' . "\n"; if ($this->managingEditor) $feedContent .= ' ' . $this->_clear_email($this->managingEditor) . '' . "\n"; if ($this->webMaster) $feedContent .= ' ' . $this->_clear_email($this->webMaster) . '' . "\n"; if ($this->pubDate) $feedContent .= ' ' . $this->pubDate . '' . "\n"; if (!$this->lastBuildDate) $this->lastBuildDate = date('r'); $feedContent .= ' ' . $this->lastBuildDate . '' . "\n"; if ($this->category) { if ($this->category['domain']) { $feedContent .= ' ' . $this->_clear_string($this->category['name']) . '' . "\n"; } else { $feedContent .= ' ' . $this->_clear_string($this->category['name']) . '' . "\n"; } } if ($this->generator) $feedContent .= ' ' . $this->_clear_string($this->generator) . '' . "\n"; if ($this->docs) $feedContent .= ' ' . $this->_clear_url($this->docs) . '' . "\n"; if ($this->cloud) $feedContent .= ' ' . "\n"; if ($this->ttl) $feedContent .= ' ' . $this->ttl . '' . "\n"; if ($this->image['url']) { $feedContent .= ' ' . "\n" . ' ' . $this->_clear_string($this->image['title']) . '' . "\n" . ' ' . $this->_clear_url($this->image['link']) . '' . "\n" . ' ' . $this->_clear_url($this->image['url']) . '' . "\n"; if ($this->image['width'] > 0) $feedContent .= ' ' . $this->image['width'] . '' . "\n"; if ($this->image['height'] > 0) $feedContent .= ' ' . $this->image['height'] . '' . "\n"; if ($this->image['description']) $feedContent .= ' ' . $this->_clear_string($this->image['description']) . '' . "\n"; $feedContent .= ' ' . "\n"; } if ($this->textInput) { $feedContent .= ' ' . "\n" . ' ' . $this->_clear_string($this->textInput['title']) . '' . "\n" . ' ' . $this->_clear_string($this->textInput['description']) . '' . "\n" . ' ' . $this->_clear_string($this->textInput['name']) . '' . $this->_clear_url($this->textInput['link']) . '' . "\n" . ' ' . "\n"; } if (is_array($this->skipHours) && sizeof($this->skipHours) > 0) { $feedContent .= ' ' . "\n"; foreach ($this->skipHours as $hour) { $feedContent .= ' ' . $hour . '' . "\n"; } $feedContent .= ' ' . "\n"; } if (is_array($this->skipDays) && sizeof($this->skipDays) > 0) { $feedContent .= ' ' . "\n"; foreach ($this->skipHours as $day) { $feedContent .= ' ' . $day . '' . "\n"; } $feedContent .= ' ' . "\n"; } if (is_array($this->xElements) && sizeof($this->xElements) > 0) { foreach($this->xElements as $xtag => $xval) { $xtagE = $xtag; if(is_array($xval)) { foreach($xval as $xvalItem) { $feedContent .= ' <' . $xtag . '>' . $xvalItem . '' . "\n"; } } else { $feedContent .= ' <' . $xtag . '>' . $xval . '' . "\n"; } } } for($i=0,$n=sizeof($this->item['title']);$i<$n;$i++) { $feedContent .= ' ' . "\n" . ' ' . $this->_clear_string($this->item['title'][$i]) . '' . "\n" . ' ' . $this->_clear_url($this->item['link'][$i]) . '' . "\n"; if ($this->item['comments'][$i]) $feedContent .= ' ' . $this->_clear_url($this->item['comments'][$i]) . '' . "\n"; if ($this->description_out == true && $this->item['description'][$i]) { $feedContent .= ' ' . $this->_clear_string($this->item['description'][$i], $this->description_out_max) . '' . "\n"; } if ($this->item['author'][$i]) $feedContent .= ' ' . $this->_clear_email($this->item['author'][$i]) . '' . "\n"; if($this->item['enclosure'][$i] !== false && $this->item['enclosure'][$i] != '' && is_file(DIR_FS_CATALOG . DIR_WS_IMAGES . $this->item['enclosure'][$i])) { $imageinfo = getimagesize(DIR_FS_CATALOG . DIR_WS_IMAGES . $this->item['enclosure'][$i]); $feedContent .= ' ' . "\n"; } if ($this->item['guid'][$i]) $feedContent .= ' ' . $this->_clear_url($this->item['guid'][$i]['url']) . '' . "\n"; if ($this->item['pubDate'][$i]) $feedContent .= ' ' . $this->item['pubDate'][$i] . '' . "\n"; else $feedContent .= ' ' . date('r') . '' . "\n"; if ($this->item['source'][$i]) $feedContent .= ' ' . $this->_clear_string($this->item['source'][$i]['name']) . '' . "\n"; if ($this->item['category'][$i] !== false && is_array($this->item['category'][$i])) { foreach ($this->item['category'][$i] as $category) { if(isset($category['domain']) && $category['domain'] != '') { $feedContent .= ' ' . $this->_clear_string($category['name']) . '' . "\n"; } else { $feedContent .= ' ' . $this->_clear_string($category['name']) . '' . "\n"; } } } foreach($this->item['ext_tags'][$i] as $xtag => $xval) { $xtagE = $xtag; if(preg_match('@^(.*):(.*) type="(.*)"$@', $xtag, $m)) { $xtagE = $m[1] . ':' . $m[2]; // var_dump($xtag, $xtagE, $m);echo '
'; } if(is_array($xval)) { foreach($xval as $xvalItem) { $feedContent .= ' <' . $xtag . '>' . $xvalItem . '' . "\n"; } } else { $feedContent .= ' <' . $xtag . '>' . $xval . '' . "\n"; } } $feedContent .= '
' . "\n"; } $feedContent .= '
' . "\n" . '
' . "\n"; return $feedContent; } function rss_feed_out() { if($this->rssFeedCahcheFrom == false) { $this->rssFeedContent = $this->rss_feed_content(); $this->rssFeedTimeCreated = time(); if($this->rssFeedCahcheFlag == true) { if (($f = fopen($this->rssFeedCahcheFileName, 'w'))) { fwrite($f, $this->rssFeedContent, strlen($this->rssFeedContent)); fclose($f); } } } header('Last-Modified: ' . gmdate("r", $this->rssFeedTimeCreated) . ' GMT'); header('Expires: ' . gmdate("r", ($this->rssFeedTimeCreated+($this->ttl*60))) . ' GMT'); header("Content-Type: " . $this->content_type . "; charset=" . $this->encoding); header("Content-disposition: inline; filename=rss.xml"); echo $this->rssFeedContent; } function rss_feed_cache($zf_query, $time=false) { $this->rssFeedCahcheFrom = false; $this->rss_feed_cache_flush($time); $this->rssFeedCahcheFileName = DIR_FS_RSSFEED_CACHE . '/rssfeed_' . md5($zf_query); if($this->rssFeedCahcheFlag && is_writable($this->rssFeedCahcheFileName)) { if(($this->rssFeedContent = file_get_contents($this->rssFeedCahcheFileName))) { // $this->rssFeedContent = unserialize($this->rssFeedContent); $this->rssFeedTimeCreated = filemtime($this->rssFeedCahcheFileName); $this->rssFeedCahcheFrom = true; } } return $this->rssFeedCahcheFrom; } function rssFeedCahcheSet($flag) { $this->rssFeedCahcheFlag = ($flag === true) ? true : false; } function rss_feed_cache_flush($time=false) { if ($za_dir = @dir(DIR_FS_RSSFEED_CACHE)) { clearstatcache(); while ($zv_file = $za_dir->read()) { if (strpos($zv_file, 'rssfeed_') === 0) { if ($time == false || (time() - filemtime(DIR_FS_RSSFEED_CACHE . '/' . $zv_file)) < $time) { @unlink(DIR_FS_RSSFEED_CACHE . '/' . $zv_file); } } } $za_dir->close(); } } function _clear_string($str, $max_leng=0) { $in[] = '@&(amp|#038);@i'; $out[] = '&'; $in[] = '@&(#036);@i'; $out[] = '$'; $in[] = '@&(quot);@i'; $out[] = '"'; $in[] = '@&(#039);@i'; $out[] = '\''; $in[] = '@&(nbsp|#160);@i'; $out[] = ' '; $in[] = '@&(hellip|#8230);@i'; $out[] = '...'; $in[] = '@&(copy|#169);@i'; $out[] = '(c)'; $in[] = '@&(trade|#129);@i'; $out[] = '(tm)'; $in[] = '@&(lt|#60);@i'; $out[] = '<'; $in[] = '@&(gt|#62);@i'; $out[] = '>'; $in[] = '@&(laquo);@i'; $out[] = ''; $in[] = '@&(raquo);@i'; $out[] = ''; $in[] = '@&(deg);@i'; $out[] = ''; $in[] = '@&(mdash);@i'; $out[] = ''; $in[] = '@&(reg);@i'; $out[] = ''; $str = preg_replace($in, $out, $str); $s = strpos($str, ''); while($s !== false && $f !== false && $f > $s) { $str = substr($str, 0, $s) . substr($str, $f+3); $s = strpos($str, ''); } $str = trim($str); if($max_leng > 0 && strlen($str) > $max_leng) { $str = substr($str, 0, $max_leng) . '...'; } if ( preg_match( "/['\"\[\]<>&]/", $str ) ) { if(RSS_STRIP_TAGS == 'true') { $st_in[] = '@
@i'; $st_out[] = "\n"; $st_in[] = '@
@i'; $st_out[] = "\n"; $st_in[] = '@
@i'; $st_out[] = "\n"; $st_in[] = '@
  • @i'; $st_out[] = "\n".chr(160); $st_in[] = '@@i'; $st_out[] = "\n\n"; $st_in[] = '@@i'; $st_out[] = "\n\n"; $st_in[] = '@

    @i'; $st_out[] = "\n"; $st_in[] = '@

    @i'; $st_out[] = "\n"; $str = preg_replace($st_in, $st_out, $str); $str = strip_tags($str); $str = htmlspecialchars($str, ENT_QUOTES); } else { $str = ""; } } if($str == '') $str = false; return $str; } function _clear_url($str) { $url_parts = parse_url($str); $out = ''; if(isset($url_parts["scheme"])) $out .= $url_parts["scheme"] . '://'; if(isset($url_parts["host"])) $out .= $url_parts["host"]; if(isset($url_parts["port"])) $out .= ':' . $url_parts["port"]; if(isset($url_parts["path"])) { $pathinfo = pathinfo($url_parts["path"]); if(!isset($pathinfo["dirname"]) || $pathinfo["dirname"] == '\\' || $pathinfo["dirname"] == '.') $pathinfo["dirname"] = ''; $out .= rtrim($pathinfo["dirname"], '/') . '/'; if($pathinfo["basename"] != '') { $out .= str_replace('&', '%26', rawurlencode($pathinfo["basename"])); } } if(isset($url_parts["query"])) { $url_parts["query"] = str_replace('&', '&', $url_parts["query"]); $url_parts["query"] = str_replace('&&', '&', $url_parts["query"]); $url_parts["query"] = str_replace('&', '&', $url_parts["query"]); $out .= '?' . $url_parts["query"]; } if(isset($url_parts["fragment"])) $out .= '#' . $url_parts["fragment"]; return $out; } function _clear_email($str) { $out = str_replace(array('<', '>'), array('(', ')'), $str); return $out; } } // EOF