and html isn't stripped | // | anymore. Gives you a nice preview with links and images. | // | | // | changelog, 2005-05-30: | // | | // | - fixed pubDate value that was set to CEST timezone and now we generate | // | valid rss 2.0 | // | | // +---------------------------------------------------------------------------+ // | | // | This program is free software; you can redistribute it and/or | // | modify it under the terms of the GNU General Public License | // | as published by the Free Software Foundation; either version 2 | // | of the License, or (at your option) any later version. | // | | // | This program is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software Foundation, | // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | // | | // +---------------------------------------------------------------------------+ /** * Geeklog RSS 2.0 class * * Parts of this code have originally been lifted from phpweblog which is * licenced under the GPL. It has since been heavily modified. * * @author Dirk Haun , Michael Jervis * @package net.geeklog.rss * */ class Rss20 { /** * @access private * @var string */ var $_feedfile = 'geeklog.rdf'; /** * @access private * @var string */ var $_feedpath = ''; /** * @access private * @var string */ var $_feedurl = ''; /** * @access private * @var string */ var $_sitelink = ''; /** * @access private * @var string */ var $_feedtitle = ''; /** * @access private * @var string */ var $_feeddesc = ''; /** * @access private * @var string */ var $_feedlang = 'en-gb'; /** * @access private * @var string */ var $_feedencoding = 'UTF-8'; /** * @access private * @var int */ var $_feedcontentlen = 0; /** * Constructor * * Initializes private variables. * * @author Dirk Haun * @access public * */ function Rss20 () { global $_CONF; if (!empty ($_CONF['default_charset'])) { $this->_feedencoding = $_CONF['default_charset']; } else { $this->_feedencoding = 'UTF-8'; } if (!empty ($_CONF['rdf_language'])) { $this->_feedlang = $_CONF['rdf_language']; } else { $this->_feedlang = $_CONF['locale']; } } /** * Set file name for the RSS feed. * * @param string filename actual file name, e.g. 'geeklog.rdf' * * @author Dirk Haun * @access public * */ function setFeedfile ($filename = '') { global $_CONF; if (!empty ($filename)) { $this->_feedfile = $filename; } else { $pos = strrpos ($_CONF['rdf_file'], '/'); $this->_feedfile = substr ($_CONF['rdf_file'], $pos + 1); } $path = $_CONF['rdf_file']; $pos = strrpos ($path, '/'); $path = substr ($path, 0, $pos + 1); $this->_feedpath = $path . $this->_feedfile; $this->_feedurl = substr_replace ($path, $_CONF['site_url'], 0, strlen ($_CONF['path_html']) - 1); } /** * Set information for an RSS feed. * * @param string link link to the site where this feed originates * @param string title (short) title of the feed * @param string desc (longer) description of the feed * * @author Dirk Haun * @access public * */ function setFeedinfo ($link = '', $title = '', $desc = '') { $this->_sitelink = $link; $this->_feedtitle = $title; $this->_feeddesc = $desc; } /** * Set formats for an RSS feed. * * @param int contentlen length of the content of an entry * @param string language feed language, e.g. 'en-gb' * @param string encoding feed encoding, e.g. 'UTF-8' * * @author Dirk Haun * @access public * */ function setFeedformats ($contentlen = 0, $language = '', $encoding = '') { $this->_feedcontentlen = $contentlen; if (!empty ($language)) { $this->_feedlang = $language; } if (!empty ($encoding)) { $this->_feedencoding = $encoding; } } /** * Format the content of an item * * @author Dirk Haun * @access private * */ function _formatContent ($text) { // fix \r = CR $storytext = preg_replace ("/(\015)/", "", $text); if ($this->_feedcontentlen > 1) { if (strlen ($storytext) > $this->_feedcontentlen) { $storytext = substr ($storytext, 0, $this->_feedcontentlen - 3) . " ..."; // Check if we broke html tag and storytext is now something // like "blah blah strrpos($storytext, ">")) { $storytext = substr ($storytext, 0, strrpos($storytext, "<") - 1) . " ..."; } } } return $storytext; } /** * Turns a UID into an author name * * @author Michael Jervis (mike AT fuckingbrit DOT com) * @access private */ function _uid2author( $uid ) { global $_TABLES; return DB_GetItem( $_TABLES['users'], 'username', "uid='$uid'" ); } /** * Write the actual feed file. * * @author Michael Jervis (mike AT fuckingbrit DOT com) * @access public * */ function write ($content) { global $LANG01, $_CONF; global $_TABLES; if (sizeof ($content) == 0) { return false; } $success = false; if ($fd = @fopen ($this->_feedpath, 'w')) { fputs( $fd, "_feedencoding . "\"?>\n\n" ); fputs( $fd, "\n" ); fputs( $fd, "\n\n" ); /* Required RSS 2.0 elements for channel: */ fputs( $fd, "<![CDATA[" .htmlspecialchars( $this->_feedtitle )."]]>\n" ); fputs( $fd, "" .htmlspecialchars( $this->_sitelink )."\n" ); fputs( $fd, "_feeddesc )."]]>\n" ); /* Optional RSS 2.0 elements for channel: */ fputs( $fd, "" .htmlspecialchars( $_CONF['site_mail'] )."\n" ); fputs( $fd, "" .htmlspecialchars( $_CONF['site_mail'] )."\n" ); fputs( $fd, "" .htmlspecialchars( $this->_feedlang )."\n" ); fputs( $fd, "\n" ); fputs( $fd, "" .gmstrftime( "%a, %d %b %Y %T %Z" )."\n" ); fputs( $fd, "Geeklog ".VERSION."\n" ); fputs( $fd, "\n\n" ); fputs( $fd, " " .htmlspecialchars( $this->_sitelink )."/images/feed.gif\n" ); fputs( $fd, " <![CDATA[" .htmlspecialchars( $this->_feedtitle )."]]>\n" ); fputs( $fd, " " .htmlspecialchars( $this->_sitelink )."\n" ); fputs( $fd, "\n" ); foreach ($content as $entry) { /* Single item content */ fputs( $fd, "\n\n" ); fputs( $fd, " " .htmlspecialchars ($entry['title']) ."\n" ); // Cannot use thisone as we don't have the compulsory email address to display // and we promised our users not to publish their address ... // fputs( $fd, " " .htmlspecialchars (DB_GetItem( $_TABLES['users'], 'username', // "uid='".$entry['uid']."'" )) . "\n"); fputs( $fd, " " .htmlspecialchars ($entry['link']) ."\n"); fputs( $fd, " " .htmlspecialchars( $entry['link'] )."\n"); fputs( $fd, " " .htmlspecialchars( gmstrftime( "%a, %d %b %Y %T %Z", $entry['date'] ) ) ."\n" ); fputs( $fd, " " .htmlspecialchars( $entry['link'].'#comments' )."\n" ); $desc = ""; if ($this->_feedcontentlen > 0) { $desc = " _formatContent ($entry['text']) . "]]>\n"; } if (!empty ($desc)) { fputs ($fd, $desc); } fputs ($fd, "\n"); } fputs ($fd, "\n"); fclose ($fd); $success = true; } else { COM_errorLog ($LANG01[54] . ' ' . $this->_feedpath, 1); } return $success; } } ?>