<?php
// $Id: data.inc.php,v 1.3 2005/10/22 08:37:48 ohwada Exp $

// 2005-10-01 K.OHWADA
// category, counter

// 2004/08/20 K.OHWADA
// atom feed

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

//================================================================
// What's New Module
// get aritciles from module
// WebLinks 0.94 <http://linux2.ohwada.net/>
// 2004/01/03 K.OHWADA
//================================================================

// --- change function name ---
function weblinks_new($limit=0, $offset=0)
{
	global $xoopsDB;

	$myts =& MyTextSanitizer::getInstance();

// --- change dir name ---
	$weblinksDirname = 'weblinks';

	$weblinks_url = XOOPS_URL."/modules/".$weblinksDirname;
	$table_link     = $xoopsDB->prefix("{$weblinksDirname}_link");
	$table_category = $xoopsDB->prefix("{$weblinksDirname}_category");
	$table_catlink  = $xoopsDB->prefix("{$weblinksDirname}_catlink");

	$i = 0;
	$ret = array();

	$sql1 = "SELECT * FROM $table_link ORDER BY time_update DESC";
	$res1 = $xoopsDB->query($sql1, $limit, $offset);

	while( $row1 = $xoopsDB->fetchArray($res1) )
	{
		$lid = $row1['lid'];
	
		$sql2 = "SELECT c1.cid, c1.title as cattitle FROM ".$table_category." c1, ".$table_catlink." c2 WHERE c1.cid=c2.cid AND c2.lid=".$lid;
		$row2 = $xoopsDB->fetchArray( $xoopsDB->query($sql2) );

		$ret[$i]['link']     = $weblinks_url."/singlelink.php?lid=".$lid;
		$ret[$i]['cat_link'] = $weblinks_url."/viewcat.php?cid=".$row2['cid'];

		$ret[$i]['title'] = $row1['title'];
		$ret[$i]['time']  = $row1['time_update'];

// category
		$ret[$i]['cat_name'] = $row2['cattitle'];

// counter
		$ret[$i]['hits'] = $row1['hits'];

// atom feed
		$ret[$i]['id']       = $lid;
		$ret[$i]['modified'] = $row1['time_update'];
		$ret[$i]['issued']   = $row1['time_create'];
		$ret[$i]['created']  = $row1['time_create'];
		$ret[$i]['description'] = $myts->makeTareaData4Show( $row1['description'], 0 );	// no html

		$i++;
	}

	return $ret;
}

// --- change function name ---
function weblinks_num()
{
	global $xoopsDB;

// --- change dir name ---
	$weblinksDirname = 'weblinks';

	$table_link = $xoopsDB->prefix("{$weblinksDirname}_link");

	$sql    = "SELECT count(*) FROM $table_link";
	$result = $xoopsDB->query($sql, 0, 0);
	$array  = $xoopsDB->fetchRow($result);
	$num    = $array[0];
	if (empty($num)) $num = 0;

	return $num;
}

// --- change function name ---
function weblinks_data($limit=0, $offset=0)
{
//	include_once XOOPS_ROOT_PATH."/modules/weblinks/class/link.php";

	global $xoopsDB;

// --- change dir name ---
	$weblinksDirname = 'weblinks';

	$weblinks_url = XOOPS_URL."/modules/".$weblinksDirname;
	$table_link   = $xoopsDB->prefix("{$weblinksDirname}_link");

	$i = 0;
	$ret = array();

	$sql = "SELECT * FROM $table_link ORDER BY lid";
	$result = $xoopsDB->query($sql, $limit, $offset);

	while( $row = $xoopsDB->fetchArray($result) )
	{
		$id = $row['lid'];
		$ret[$i]['id']   = $id;
		$ret[$i]['link'] = $weblinks_url."/singlelink.php?lid=$id";
		$ret[$i]['title'] = $row['title'];
		$ret[$i]['time']  = $row['time_update'];
		$i++;
	}

	return $ret;
}

?>
