<?php
// $Id: index.php,v 1.1 2004/07/11 10:28:39 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once('header.php');

if ( $xoopsConfig['startpage'] == $xoopsModule->dirname() ) {
	$xoopsOption['show_rblock'] = 1;
	include_once(XOOPS_ROOT_PATH.'/header.php');
	$start = intval($HTTP_GET_VARS['start']);
	if ( empty($start) ) {
		make_cblock();
		echo '<br />';
	}
	} else {
		$xoopsOption['show_rblock'] = 0;
		include_once(XOOPS_ROOT_PATH.'/header.php');
	}

include_once(XOOPS_ROOT_PATH.'/class/xoopspagenav.php');
include_once(XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->dirname().'/cache/config.php');
include_once('class/class.newsstory.php');

if ( isset($HTTP_GET_VARS['storytopic']) && is_numeric($HTTP_GET_VARS['storytopic']) ) {
	$xoopsOption['storytopic'] = intval($HTTP_GET_VARS['storytopic']);
	} else {
		$xoopsOption['storytopic'] = 0;
	}

if ( isset($HTTP_GET_VARS['storynum']) && is_numeric($HTTP_GET_VARS['storynum']) ) {
	$xoopsOption['storynum'] = intval($HTTP_GET_VARS['storynum']);
	} else {
		$xoopsOption['storynum'] = $newsConfig['storyhome'];
	}

if ( $newsConfig['displaynav'] == 1 ) {
	echo "<br /><form name='form1' action='./index.php' method='get'>";
	$xt = new XoopsTopic($db->prefix("topics"));
	$xt->makeTopicSelBox(1, $xoopsOption['storytopic'], "storytopic");
	echo "<select class='select' name='storynum'>";
	for ($i=5; $i<=30; $i=$i+5) {
		$sel = "";
		if ( $i == $xoopsOption['storynum'] ) {
			$sel = " selected='selected'";
		}
		echo "<option value='$i'$sel>$i</option>";
	}
	echo "</select><input type='submit' class='button' value='"._GO."' /></form>";
}

$sarray     = NewsStory::getAllPublished($xoopsOption['storynum'], $start, $xoopsOption['storytopic']);
$storycount = NewsStory::countByTopic($xoopsOption['storytopic']);
$pagenav    = new XoopsPageNav($storycount, $xoopsOption['storynum'], $start, "storytopic=".$xoopsOption['storytopic']."&amp;storynum=".$xoopsOption['storynum']."&amp;start", "");

if ($newsConfig['rss_enable'] == 1) {
	echo "<div align='right'><a href='./cache/news.xml' target='_blank'><img src='./images/xml.gif' border='0' vspace=2></a></div>";
}

foreach ($sarray as $story) {
	$poster = $story->uname();
	if ( $poster != false ) {
		$poster = "<a href='".XOOPS_URL."/userinfo.php?uid=".$story->uid()."'>".$poster."</a>";
		} else {
			$poster = $xoopsConfig['anonymous'];
		}
	$created    = formatTimestamp($story->published());
	$hometext   = $story->hometext();
	$introcount = strlen($hometext);
	$fullcount  = strlen($story->bodytext());
	$totalcount = ($introcount + $fullcount);
	$morelink   = "";
	if ( $fullcount > 1 ) {
		$morelink .= "<a href='".XOOPS_URL."/modules/".$xoopsModule->dirname()."/article.php?storyid=".$story->storyid()."";
		$morelink .= "'><b>"._NW_READMORE."</b></a> | ";
		$morelink .= sprintf(_NW_BYTESMORE, $totalcount);
		$morelink .= " | ";
	}

$count     = $story->getCommentsCount();
$morelink .= "<a href='".XOOPS_URL."/modules/".$xoopsModule->dirname()."/article.php?storyid=".$story->storyid()."";
$morelink2 = "<a href='".XOOPS_URL."/modules/".$xoopsModule->dirname()."/article.php?storyid=".$story->storyid()."";

if ($count == 0) {
	$morelink .= "'>"._NW_COMMENTS."?</a>";
	} else {
		if ($fullcount < 1) {
			if ($count == 1) {
				$morelink .= "'><b>"._NW_READMORE."</b></a> | $morelink2'>"._NW_ONECOMMENT."</a>";
				} else {
					$morelink .= "'><b>"._NW_READMORE."</b></a> | $morelink2'>";
					$morelink .= sprintf(_NW_NUMCOMMENTS, $count);
					$morelink .= "</a>";
				}
			} else {
				if ($count == 1) {
					$morelink .= "'>"._NW_ONECOMMENT.'</a>';
					} else {
						$morelink .= "'>";
						$morelink .= sprintf(_NW_NUMCOMMENTS, $count);
						$morelink .= '</a>';
					}
			}
	}
	$thetext    = $hometext;
	$storytopic = $story->topic();
	$adminlink  = '&nbsp;';

	if ($xoopsUser) {
		if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
			$adminlink = $story->adminlink();
		}
	}

	$imglink = '';
	if ( $story->topicdisplay() ) {
		$imglink = $story->imglink();
	}

	$title = $story->textlink().' : '.$story->title();

	// formatting story ends here
	// now, display the story
	themenews($poster, $created, $title, $story->counter(), $thetext, $imglink, $adminlink, $morelink);
}

// Show navigation bar
echo '<div align="center">'.$pagenav->renderNav(3, 3).'</div>';

include_once(XOOPS_ROOT_PATH.'/footer.php');
?>
