<?php
// $Id: singlelink.php,v 1.4 2005/10/28 11:56:02 ohwada Exp $

// 2005-09-04 K.OHWADA
// BUG 2932: dont work correctly when register_long_arrays = off

// 2005-02-03 K.OHWADA
// add view_atomfeed_auto(), view_atomfeed_stop()

// 2005-01-20 K.OHWADA
// add rss_mode_title, rss_mode_content
// add xoops_pagetitle

// 2004-11-22 K.OHWADA
// use class.rss_parser_base.php class.rss_atom_collect.php

// 2004-10-24 K.OHWADA
// enable to modeify the display layout of a category path in the template 
// RSS / ATOM Auto Discovery

// 2004/08/10 K.OHWADA
// use class weblinksCatlink
// enable to install this module two or more. 

//================================================================
// view single link information
// use class weblinksCategory, weblinksLink
// 2004/01/14 K.OHWADA
//================================================================

include "header.php";
include XOOPS_ROOT_PATH."/header.php";

// BUG 2932: dont work correctly when register_long_arrays = off
$lid = get_get_int('lid');

$row = $tbl_link->getRowByLid($lid);
if (empty($row))
{
	$url = $MODULE_URL."/index.php";
	redirect_header($url, 2, _WLS_NOMATCH);
	exit();
}

// enable to install this module two or more. 
$xoopsOption['template_main'] = $MODULE_DIRNAME."_singlelink.html";

assignIndex();

$title     = $tbl_link->get_field_value_text('title', 'S');
$pagetitle = $MODULE_NAME.' - '.$title;
$xoopsTpl->assign('xoops_pagetitle', $pagetitle);

$cid_arr = $tbl_catlink->getCidArrayByLid($lid);

$tbl_category->getAll();

// enable to modeify the display layout of a category path in the template 
foreach ($cid_arr as $cid)
{
	$catpath = $tbl_category->getParentPath($cid);
	$xoopsTpl->append('catpaths', $catpath);
}

$xoopsTpl->assign('link', $tbl_link->makeDisplay());
assignDisplayLink();

view_atomfeed( $tbl_link->lid );

include XOOPS_ROOT_PATH.'/include/comment_view.php';
include XOOPS_ROOT_PATH.'/footer.php';

exit();


//---------------------------------------------------------
// view ATOM feed
// RSS/ATOM auto discovery
//---------------------------------------------------------
function view_atomfeed($lid)
{
	global $weblinksConfig;

	if ( $weblinksConfig['rss_mode_auto'] )
	{
		view_atomfeed_auto($lid);
	}
	else
	{
		view_atomfeed_stop();
	}
}


function view_atomfeed_stop()
{
	global $xoopsTpl;

	$xoopsTpl->assign('rss_flag',   0 );

}

function view_atomfeed_auto($lid)
{
	global $xoopsTpl;
	global $MODULE_ROOT;
	global $weblinksConfig;

	include_once $MODULE_ROOT.'/class/class.rss_atom_parser_base.php';
	include_once $MODULE_ROOT.'/class/class.rss_parser.php';
	include_once $MODULE_ROOT.'/class/class.atom_parser.php';
	include_once $MODULE_ROOT.'/class/rss_atom_collect.php';

	$xoopsTpl->assign('rss_num_content', $weblinksConfig['rss_num_content'] );

	$collect = new rss_atom_collect();
	$collect->set_mode_auto(    $weblinksConfig['rss_mode_auto'] );
	$collect->set_mode_data(    $weblinksConfig['rss_mode_data'] );
	$collect->set_cache_time(   $weblinksConfig['rss_cache_time'] );
	$collect->set_num_feed(     $weblinksConfig['rss_perpage'] );
	$collect->set_mode_title(   $weblinksConfig['rss_mode_title'] );
	$collect->set_mode_content( $weblinksConfig['rss_mode_content'] );
	$collect->set_max_content(  $weblinksConfig['rss_max_content'] );
	$collect->set_max_summary(  $weblinksConfig['rss_max_summary'] );

	$feeds = $collect->parse_xml_for_singlelink($lid);
	if ($feeds)
	{
		assign_feeds($feeds);
	}

	$xoopsTpl->assign('rss_flag',   $collect->get_rss_flag() );
	$xoopsTpl->assign('rss_url',    $collect->get_rss_url() );
	$xoopsTpl->assign('rss_update', $collect->get_rss_update("m") );

}

function assign_feeds($feeds)
{
	global $xoopsTpl;

	if ( !is_array($feeds) )  return false;

	$count = count($feeds);
	if ($count <= 0)  return false;

	for ($i=0; $i<$count; $i++)
	{
		$xoopsTpl->append_by_ref('feeds', $feeds[$i]);
	}
}

?>
