<?php
$cache = RayCache::getInstance('home', null, array('prefix' => $setting['theme'], 'path' => 'cache/', 'expire' => $setting['cachelife']));
$data = $cache->read('home');
if ($data) {
	echo $data;
} else {
	$cache->start_caching();

$pic_settings = array('w'=>80,'h'=>80);
?>
<!-- begin center -->
<div id="center"> 
<div id="home_container">
<!-- start of banner box -->
<div id="banner"><div id="nav2">Banner</div>
<div align="center" style="padding:2px">
<?php
if (ad("8") == "Put AD code here") {
?>
<img src="<?php echo $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/100x100banner.png';?>" width="100" height="100" />
<?php
} else {
	echo ad("8");	
}
?>
</div></div>
<!-- end of banner box -->
<!-- start of news box -->
<div id="news"><div id="nav1">News</div>
<div align="left" style="padding:6px">
<?php
        $sql = yasDB_select("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 1",false);		
        $news = $sql->fetch_array(MYSQLI_ASSOC);		
        $text = strlen($news['news_text'])>130?substr($news['news_text'],0,130).'...':$news['news_text'];				
        echo '<center><b>'. $news['date'] . '</center></b>			
              <left>'. $text. '</left>				  
              <div style="position:absolute;bottom:0px;right:70px;"><a href="' . $setting['siteurl'] . 'news.html">Read All News</a></div>';        	
        $sql->close();		
?>
</div>
</div>
<!-- end of news box -->
<!-- start of banner box -->
<div id="banner2"><div id="nav2">Banner</div>
<div align="center" style="padding:2px">
<?php
if (ad("10") == "Put AD code here") {
?>
<img src="<?php echo $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/100x100banner.png';?>" width="100" height="100" />
<?php
} else {
	echo ad("10");	
}
?>
</div></div>
<!-- end of banner box -->
<!-- start of mostplayed box -->
<div id="mostplayed"><div id="nav5">Most Played</div>
<?php
$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games ORDER BY plays DESC LIMIT 9");
if ($query->num_rows == 0) {
	echo '<center><h3>We have no Most Played games yet!</h3></center>';
} else {
	$pic_settings = array('w'=>80,'h'=>80);
	while($games = $query->fetch_array(MYSQLI_ASSOC)) {
		$gameurl = prepgame($games['title']);
		if (strlen($games['title']) > 19) {
		$games['title'] = substr($games['title'], 0, 16) . '...';
		} else {
		$games['title'] = $games['title'];
		}
		if (file_exists($games['thumbnail'])) {
			$thumbnail = urldecode($games['thumbnail']);
		} else {
			$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
	}
		if ($setting['seo']=='yes') {
			$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
		} else {
			$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
		}
		?>
		<div class="inner_box3"><a href="<?php echo $gurl;?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?>  Plays">		
		<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" width="80" height="80" /></a>		
		</div>		
	<?php
	}
}
$query->close();
?>
</div>
<!-- end of mostplayed box -->
<!-- start of random box -->
<div id="random"><div id="nav6">Random Games</div>
<?php           
	$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games ORDER BY rand() LIMIT 4");
	if ($query->num_rows == 0) {
		echo '<center><h3>We have no Random games yet!</h3></center>';
	} else {
		$pic_settings = array('w'=>100,'h'=>100);
		while($games = $query->fetch_array(MYSQLI_ASSOC)) {		
			$gameurl = prepgame($games['title']);				
			$games['description'] = stripslashes($games['description']);
			$description = str_replace(array("\r\n", "\r", "\n"), ' ', $games['description']);
            $description = str_replace("'", "\'", $description);
			$description = str_replace('"', '\"', $description);
			if (strlen($games['title']) > 19) {
			$games['title'] = substr($games['title'], 0, 16) . '...';
			} else {
			$games['title'] = $games['title'];
			}
			if (file_exists($games['thumbnail'])) {
			$thumbnail = urldecode($games['thumbnail']);
			} else {
			$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
			}		
			if ($setting['seo']=='yes') {
			$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
			} else {
			$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
			}
			?>
			<div class="inner_box2">		
			<a href="<?php echo $gurl;?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays">		
			<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" width="100" height="100" /></a>		
			<a href="<?php echo $gurl;?>" class="hintanchor" onMouseover="showhint('<b>Description</b><br><?php echo $description;?>', this, event, '200px')"><?php echo $games['title'];?></a>		
			<div class="clear"></div><br style="clear: both"/></div>
<?php 
		}
	}
$query->close();?>
</div>
<!-- end of random box -->
<br style="clear: both"/>
<!-- start of featured box -->
<div class="container_box1"><div class="header">Featured Games</div>
<?php
	$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games WHERE id IN (SELECT gameid from featuredgames) ORDER BY rand()");
	$pic_settings = array('w'=>130,'h'=>100);
	if ($query->num_rows == 0) {
		$query->close();
		$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games ORDER BY rand() LIMIT 5");
		if ($query->num_rows == 0) {
			echo '<center><h3>We have no Featured games yet!</h3></center>';
		}
	}
	if ($query->num_rows > 0) {
		while($games = $query->fetch_array(MYSQLI_ASSOC)){	
		$gameurl = prepgame($games['title']);			
		$games['description'] = stripslashes($games['description']);
		$description = str_replace(array("\r\n", "\r", "\n"), ' ', $games['description']);
        $description = str_replace("'", "\'", $description);
		$description = str_replace('"', '\"', $description);
        if (strlen($games['title']) > 19) {
		$games['title'] = substr($games['title'], 0, 16) . '...';
		} else {
		$games['title'] = $games['title'];
		}
		if (file_exists($games['thumbnail'])) {
			$thumbnail = urldecode($games['thumbnail']);
		} else {
			$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
		}
		if ($setting['seo']=='yes') {
			$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
		} else {
			$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
		}
	?>	
		<div class="inner_box"><div class="images">		
		<a href="<?php echo $gurl;?>">		
		<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays" width="130" height="100" /></a>		
		<div class="text2">
		<a href="<?php echo $gurl;?>" class="hintanchor" onMouseover="showhint('<b>Description</b><br><?php echo $description;?>', this, event, '200px')"><?php echo $games['title'];?></a></div>
		</div>
		<div class="clear"></div><br style="clear: both"/></div>	
<?php 
			}
		}
$query->close();
?>
<div class="clear"></div></div>
<!-- end of featured box -->
<!-- start of ads_box box -->
<div class="container_box1" style="min-height:0px">
<div class="header">Advertisement</div>
<div class="container_box3"><div class="container_box4">
<?php 	
if (ad("4") == 'Put AD code here') {
	?><img src="<?php echo $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/468x60.PNG';?>" width="468" height="60" />
	<?php	
} else {
	echo ad("4");
}
?>
</div></div>
<div class="clear"></div>
</div>
<!-- end of ads box -->
<!-- start of toprated -->

<div class="container_box1"><div class="header">Top Rated</div>
<?php
$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM `games` WHERE `id` IN (SELECT id FROM `ratingsbar` ORDER BY total_value/total_votes) ORDER BY plays DESC LIMIT 5",false);
if ($query->num_rows == 0) {
	$query->close();
	$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games ORDER BY rand() LIMIT 5");
	if ($query->num_rows == 0) {
		echo '<center><h3>We have no Top Rated games yet!</h3></center>';
	}
}
if ($query->num_rows > 0) {
	$pic_settings = array('w'=>130,'h'=>100);
	while($games = $query->fetch_array(MYSQLI_ASSOC)) {
		$gameurl = prepgame($games['title']);				
		$games['description'] = stripslashes($games['description']);
		$description = str_replace(array("\r\n", "\r", "\n"), ' ', $games['description']);
        $description = str_replace("'", "\'", $description);
		$description = str_replace('"', '\"', $description);
	    if (strlen($games['title']) > 19) {
		$games['title'] = substr($games['title'], 0, 16) . '...';
		} else {
		$games['title'] = $games['title'];
		}
		if (file_exists($games['thumbnail'])) {
			$thumbnail = urldecode($games['thumbnail']);
		} else {
			$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
		}		
		if ($setting['seo']=='yes') {
			$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
		} else {
			$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
		}
	?>
		<div class="inner_box"><div class="images">		
		<a href="<?php echo $gurl;?>">		
		<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays" width="130" height="100" /></a>
		</div>		
		<div class="text2">
		<a href="<?php echo $gurl;?>" class="hintanchor" onMouseover="showhint('<b>Description</b><br><?php echo $description;?>', this, event, '200px')"><?php echo $games['title'];?></a>		
		</div>
		<div class="clear"></div><br style="clear: both"/></div>
	<?php	
	}
}
$query->close();
?>
<div class="clear"></div></div>
<!-- end of toprated -->
<!-- start of newest games box -->

<div class="container_box1"><div class="header">Newest Games</div>
<?php
$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games ORDER BY id DESC LIMIT 5",false);
if ($query->num_rows == 0) {
	echo '<center><h3>We have no Top Rated games yet!</h3></center>';
}
if ($query->num_rows > 0) {
	$pic_settings = array('w'=>130,'h'=>110);
	while($games = $query->fetch_array(MYSQLI_ASSOC)) {
		$gameurl = prepgame($games['title']);			
		$games['description'] = stripslashes($games['description']);
		$description = str_replace(array("\r\n", "\r", "\n"), ' ', $games['description']);
        $description = str_replace("'", "\'", $description);
		$description = str_replace('"', '\"', $description);
		if (strlen($games['title']) > 19) {
		$games['title'] = substr($games['title'], 0, 16) . '...';
		} else {
		$games['title'] = $games['title'];
		}
		if (file_exists($games['thumbnail'])) {
			$thumbnail = urldecode($games['thumbnail']);
		} else {
			$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
		}
		if ($setting['seo']=='yes') {
			$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
		} else {
			$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
		}
	?>
		<div class="inner_box"><div class="images">		
		<a href="<?php echo $gurl;?>">		
		<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays" width="130" height="100" /></a>
		</div>
		<div class="text2">
		<a href="<?php echo $gurl;?>" class="hintanchor" onMouseover="showhint('<b>Description</b><br><?php echo $description;?>', this, event, '200px')"><?php echo $games['title'];?></a>		
		</div><div class="clear"></div><br style="clear: both"/></div>
	<?php	
	}
}	
$query->close();
?>               
<div class="clear"></div></div>
<!-- end of newest games box -->
<div class="container_box1"><div class="header">Category Games</div>
<?php
    $query1 = yasDB_select("SELECT id FROM categories WHERE active='yes' ORDER BY id LIMIT 5");
	while($category = $query1->fetch_array(MYSQLI_ASSOC)) {
		$query = yasDB_select("SELECT id, title, thumbnail, description, plays FROM games WHERE category={$category['id']} ORDER BY rand() LIMIT 1",true);
		$pic_settings = array('w'=>130,'h'=>100);
		while($games = $query->fetch_array(MYSQLI_ASSOC)) {
			$gameurl = prepgame($games['title']);			
			$games['description'] = stripslashes($games['description']);
			$description = str_replace(array("\r\n", "\r", "\n"), ' ', $games['description']);
            $description = str_replace("'", "\'", $description);
			$description = str_replace('"', '\"', $description);	
			if (strlen($games['title']) > 19) {
			$games['title'] = substr($games['title'], 0, 16) . '...';
			} else {
			$games['title'] = $games['title'];
			}
			if (file_exists($games['thumbnail'])) {
				$thumbnail = urldecode($games['thumbnail']);
			} else {
				$thumbnail = $setting['siteurl'].'templates/'.$setting['theme'].'/skins/'.$setting['skin'].'/images/nopic.jpg';
			}		
			if ($setting['seo']=='yes') {
				$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
			} else {
				$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
			}
			?>
			<div class="inner_box"><div class="images">		
			<a href="<?php echo $gurl;?>">		
			<img align="absmiddle" src="<?php echo resize($thumbnail, $pic_settings);?>" title="<?php echo $games['title'];?> - <?php echo $games['plays'];?> Plays" width="130" height="100" /></a>
			</div>
			<div class="text2">
			<a href="<?php echo $gurl;?>" class="hintanchor" onMouseover="showhint('<b>Description</b><br><?php echo $description;?>', this, event, '200px')"><?php echo $games['title'];?></a>		
			</div><div class="clear"></div><br style="clear: both"/></div>
			<?php 
		}
	}
?>
<div class="clear"></div></div>
</div>
<?php
$cache->write('home');
$cache->stop_caching();
echo $cache->read('home');
}
?>