Source for file rss_lib.php
Documentation is available at rss_lib.php
* @version $Header: /cvsroot/bitweaver/_bit_rss/rss_lib.php,v 1.11 2007/01/06 09:46:24 squareing Exp $
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
* Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
* $Id: rss_lib.php,v 1.11 2007/01/06 09:46:24 squareing Exp $
$findesc= "%" . $find . "%";
$mid = " where (`name` like ? or `description` like ?)";
$bindvars= array($findesc,$findesc);
$query = "select * from `". BIT_DB_PREFIX. "rss_modules` $mid order by ". $this->mDb->convertSortmode($sort_mode);
$query_cant = "select count(*) from `". BIT_DB_PREFIX. "rss_modules` $mid";
$result = $this->mDb->query($query,$bindvars,$max_records,$offset);
$cant = $this->mDb->getOne($query_cant,$bindvars);
while ($res = $result->fetchRow()) {
$res["minutes"] = $res["refresh"] / 60;
function replace_rss_module($rss_id, $name, $description, $url, $refresh, $show_title, $show_pub_date) {
//if($this->rss_module_name_exists($name)) return false; // TODO: Check the name
$refresh = 60 * $refresh;
$query = "update `". BIT_DB_PREFIX. "rss_modules` set `name`=?,`description`=?,`refresh`=?,`url`=?,`show_title`=?,`show_pub_date`=? where `rss_id`=?";
$bindvars= array($name,$description,$refresh,$url,$show_title,$show_pub_date,$rss_id);
// was: replace into, no clue why.
$query = "insert into `". BIT_DB_PREFIX. "rss_modules`(`name`,`description`,`url`,`refresh`,`content`,`last_updated`,`show_title`,`show_pub_date`)
values(?,?,?,?,?,?,?,?)";
$bindvars= array($name,$description,$url,$refresh,'',1000000,$show_title,$show_pub_date);
$result = $this->mDb->query($query,$bindvars);
$query = "delete from `". BIT_DB_PREFIX. "rss_modules` where `rss_id`=?";
$result = $this->mDb->query($query,array($rss_id));
$query = "select * from `". BIT_DB_PREFIX. "rss_modules` where `rss_id`=?";
$result = $this->mDb->query($query,array($rss_id));
$ret = $result->fetchRow();
$this->buffer .= '<' . $name . '>';
if ($name == 'item' || $name == 'items') {
if ($name == 'item' || $name == 'items') {
$this->buffer .= '</' . $name . '>';
# print ("<!-- XML Parse error at " . xml_get_current_line_number($this->parser) . ": "
# . xml_error_string(xml_get_error_code($this->parser)) . " -->\n");
$news[] = array('title'=>
preg_match_all("/<dc:date>(.*?)<\/dc:date>/i", $this->buffer, $pubdate);
if (count($pubdate[1])< 1)
preg_match_all("/<pubDate>(.*?)<\/pubDate>/i", $this->buffer, $pubdate);
for ($i = 0; $i < count($titles[1]); $i++ ) {
$anew["title"] = $titles[1][$i];
if (isset ($links[1][$i])) {
$anew["link"] = $links[1][$i];
if ( isset ($pubdate[1][$i]) && ($show_pub_date == 'y') )
$anew["pubdate"] = $pubdate[1][$i];
return $this->NewsFeed($rssdata, $rss_id);
$now = $gBitSystem->getUTCTime();
$query = "update `". BIT_DB_PREFIX. "rss_modules` set `content`=?, `last_updated`=? where `rss_id`=?";
$result = $this->mDb->query($query,array((string) $data,(int) $now, (int) $rss_id));
$query = "select `name` from `". BIT_DB_PREFIX. "rss_modules` where `name`=?";
$result = $this->mDb->query($query,array($name));
return $result->numRows();
$query = "select `rss_id` from `". BIT_DB_PREFIX. "rss_modules` where `name`=?";
$id = $this->mDb->getOne($query,array($name));
$query = "select `show_title` from `". BIT_DB_PREFIX. "rss_modules` where `rss_id`=?";
$ret = $this->mDb->getOne($query,array($rss_id));
$query = "select `show_pub_date` from `". BIT_DB_PREFIX. "rss_modules` where `rss_id`=?";
$show_pub_date = $this->mDb->getOne($query,array($rss_id));
$now = $gBitSystem->getUTCTime();
// if ($info["last_updated"] + $info["refresh"] < $now) {
function rss_iconv($xmlstr, $tencod = "UTF-8") {
if (preg_match("/<\?xml.*encoding=\"(.*)\".*\?>/", $xmlstr, $xml_head)) {
// Use utf8_encode a more standard function
// UTF-8 and US-ASCII don't need convertion
// Not supported encoding, we must use iconv() or recode()
$new_xmlstr = @iconv($sencod, $tencod, $xmlstr);
if ($new_xmlstr === FALSE) {
// in_encod -> out_encod not supported, may be misspelled encoding
$sencod = strtr($sencod, array(
$new_xmlstr = @iconv($sencod, $tencod, $xmlstr);
if ($new_xmlstr === FALSE) {
// in_encod -> out_encod not supported, leave it
// Fix an iconv bug, a few garbage chars beyound xml...
$xmlstr = preg_replace("/(.*<\/rdf:RDF>).*/s", "\$1", $xmlstr);
// I don't have recode support could somebody test it?
$xmlstr = @recode_string("$sencod..$tencod", $xmlstr);
// This PHP intallation don't have any EncodConvFunc...
// somebody could create bit_iconv(...)?
// Replace header, put the new encoding
$xmlstr = preg_replace("/(<\?xml.*)encoding=\".*\"(.*\?>)/", "\$1 encoding=\"$tencod\"\$2", $xmlstr);
|