#!/usr/bin/php -f * http://bbs.docksud.com.ar * telnet://bbs.docksud.com.ar * * This file is released under GPLv2 license. * * Latest version at http://bbs.docksud.com.ar/~ragnarok/sync/rssviewer * * You must put this file in your cron as "php -f /you/rssviewer/rssviewer.php" */ error_reporting (E_ALL); require("lastRSS.php"); /** * NOTE: Maybe, you must change the ini_file path */ $ini_fname = '/sbbs/ctrl/rssviewer.ini'; // ************* you dont need edit beyon this line... ************** $config = parse_ini_file ($ini_fname,true); try { $db = new PDO('sqlite:' . $config['database']['path']); //delete the items $ret = $db->query('DELETE FROM item'); //get the sources $ret = $db->query("SELECT id,url FROM source"); } catch (PDOException $e) { printf("Error open database: %s\r\n",$e->getMessage()); die(); } $rss = new lastRSS(); $rss->cache_dir = isset($config['rss']['cache_dir']) ? $config['rss']['cache_dir'] : '/tmp'; $rss->cache_time = isset($config['rss']['cache_time']) ? $config['rss']['cache_time'] : sprintf(3600 * 6); $rss->stripHTML = true; foreach ($ret as $source) { printf ("Get %s\n",$source['url']); if (($source_rss = $rss->Get($source['url']))) { //updatig the source try { $sql = "UPDATE source SET "; $sql .= "title = '" .$source_rss['title']. "',"; if (isset($source_rss['description'])) $sql .= "description = '" . $source_rss['description'] . "',"; $sql .= "link = '" .$source_rss['link']. "',"; if (isset($source_rss['lastBuild'])) $sql .= "lastBuild = '" . $source_rss['lastBuild'] . "',"; if (isset($source_rss['generator'])) $sql .= "generator = '" . $source_rss['generator'] . "',"; if (isset($source_rss['language'])) $sql .= "language = '" . $source_rss['language'] . "'"; else $sql .= "language = ''"; $sql .= " WHERE id = " .$source['id']; $db->query($sql); } catch (PDOException $e) { printf ("Error updating source %s: %s",$source['url'],$e->getMessage()); die(); } //reading items foreach ($source_rss['items'] as $item){ $sql = "INSERT INTO item "; $sql .= "(id_source,title,link,description,category,pubDate) "; $sql .= "VALUES ("; $sql .= $source['id'] . ','; $sql .= "'" .html_entity_decode($item['title']). "',"; $sql .= "'" .$item['link']. "',"; if (isset($item['description'])) $sql .= "'" .html_entity_decode($item['description']). "',"; else $sql .= "'',"; if (isset($item['category'])) $sql .= "'" .html_entity_decode($item['category']). "',"; else $sql .= "'',"; if (isset($item['pubDate'])) $sql .= "'" .$item['pubDate']. "'"; else $sql .= "''"; $sql .= ")"; try { $db->exec($sql); } catch (PDOException $e) { printf ("Error adding the rss items: %s\r\n", $e->getMessage()); die(); } } } else { printf("Error: can't get the source %s\r\n",$row['url']); die(); } } ?>