<?php
###############################################################################
##                RSSFit - Extendable XML news feed generator                ##
##                   Copyright (c) 2004 NS Tai (aka tuff)                    ##
##                       <http://www.brandycoke.com/>                        ##
##                      Modified By 2005 CACHE RSSfitJ                       ##
##                       <http://gyakubiki.kir.jp/>                          ##
###############################################################################
##                    XOOPS - PHP Content Management System                  ##
##                       Copyright (c) 2000 XOOPS.org                        ##
##                          <http://www.xoops.org/>                          ##
###############################################################################
##  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.                                      ##
##                                                                           ##
##  You may not change or alter any portion of this comment or credits       ##
##  of supporting developers from this source code or any supporting         ##
##  source code which is considered copyrighted (c) material of the          ##
##  original comment or credit authors.                                      ##
##                                                                           ##
##  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 ##
###############################################################################
##  Author of this file: CACHE                                               ##
##  URL: http://gyakubiki.kir.jp/                                            ##
##  Project: RSSFitJ                                                         ##
###############################################################################
$module_array=array();
for ($i=0;$i<100;$i++) {
	if (isset($_GET['module'.$i])) {
		$module_array[]=$_GET['module'.$i];
	} else {
		if (isset($_POST['module'.$i]))
			$module_array[]=$_POST['module'.$i];
	}
}
if( function_exists('mb_http_output') ){
	mb_http_output('pass');
}
include 'header.php';
require_once XOOPS_ROOT_PATH.'/class/template.php';
$xoopsTpl = new XoopsTpl();
$nocache = !empty($_GET['nocache']) || !$xoopsModuleConfig['cache'] || !empty($_GET['debug']) ? true : false;
if( $nocache ){
	$xoopsTpl->xoops_setCaching(0);
}else{
	$xoopsTpl->xoops_setCaching(2);
	$xoopsTpl->xoops_setCacheTime($xoopsModuleConfig['cache']*60);
}

if( !$xoopsTpl->is_cached('db:rssfitJ_rss.html') || $nocache ){
	$criteria = new Criteria('rssfj_activated', 1);
	$criteria->setSort('rssfj_order');
	if( $plugins =& $rssfj_mgr->getObjects($criteria) ){
		$entries = array();
		foreach( $plugins as $p ){
			if( $handler =& $rssfj_mgr->checkPlugin($p) ){
				$modDir = $handler->getDirName();
				if (in_array($modDir,$module_array) ||
					count($module_array)==0) {
					$grab = $handler->grabEntries($p);
					if( count($grab) > 0 ){
						foreach( $grab as $g ){
							array_push($entries, $g);
						}
					}
				}
			}
		}
		if( count($entries) > 0 ){
			if( $xoopsModuleConfig['sort'] == 'd' ){
				uasort($entries, 'sortTimestamp');
			}
			if( count($entries) > $xoopsModuleConfig['overall_entries'] ){
				$entries = array_slice($entries, 0, $xoopsModuleConfig['overall_entries']);
			}
			foreach( $entries as $e ){
				$e['title'] = utf8Encode(htmlspecialchars($e['title'], ENT_QUOTES));
				$e['pubdate'] = rssTimeStamp($e['timestamp']);
				if( $xoopsModuleConfig['strip_html'] ){
					$e['description'] = preg_replace('/<([^>]|\n)*>/', ' ', $e['description']);
					$e['description'] = preg_replace('/\[([^>]|\n)*\]/', ' ', $e['description']);
				}
				$e['description'] = utf8Encode(htmlspecialchars(doSubstr($e['description']), ENT_QUOTES));
				$e['category'] = utf8Encode(htmlspecialchars($e['category'], ENT_QUOTES));
				$xoopsTpl->append('items', $e);
			}
		}
	}
	
	$xoopsTpl->assign('channel_title', utf8Encode(htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)));
	$xoopsTpl->assign('channel_desc', utf8Encode(htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES)));
	$sql = "SELECT conf_value FROM ".$xoopsDB->prefix('config')." WHERE conf_name = 'meta_copyright' AND conf_modid = 0 AND conf_catid = ".XOOPS_CONF_METAFOOTER;
	list($copyright) = $xoopsDB->fetchRow($xoopsDB->query($sql));
	$xoopsTpl->assign('channel_copyright', utf8Encode(htmlspecialchars($copyright, ENT_QUOTES)));
	$xoopsTpl->assign('channel_lastbuild', rssTimeStamp(time()));
	$gen = XOOPS_VERSION.' / '.RSSFITJ_VERSION;
	$xoopsTpl->assign('channel_generator', utf8Encode($gen));
	$xoopsTpl->assign('channel_editor', $xoopsConfig['adminmail']);
	$xoopsTpl->assign('channel_webmaster', $xoopsConfig['adminmail']);
	if( $xoopsModuleConfig['cache'] > 0 ){
		$xoopsTpl->assign('channel_ttl', $xoopsModuleConfig['cache']);
	}
}

if( empty($_GET['debug']) ){
	if( !$xoopsModuleConfig['utf8'] ){
		$xoopsTpl->assign('rssj_encoding', _CHARSET);
		header('Content-Type:text/xml; charset='._CHARSET);
	}else{
		$xoopsTpl->assign('rssj_encoding', 'UTF-8');
		header('Content-Type:text/xml; charset=UTF-8');
	}
}else{
	header('Content-Type:text/html; charset='._CHARSET);
}
$xoopsTpl->display('db:rssfitJ_rss.html');
?>