<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.848b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  August 13th 2006                                         //
// Version:                 PHPizabi 0.848b C1                                       //
//                                                                                   //
// (C) 2005, 2006 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	
	
	/*
		Initialize the template engine and load the
		template file
	*/
	$tpl = new template;
	$tpl -> Load("browse");
	$tpl -> ConvertSelf();
	
	/*
		Let's get the last 50 blogs and show them
	*/
	$select = myQ("SELECT * FROM `[x]blogs` ORDER BY `date` DESC LIMIT 20");
	
	/*
		... and loop inside those results, creating
		the replacement array
	*/
	$i=0;

	$blogArticle = false;

	if(myNum($select) > 0){

	while ($row = myF($select)) {

		$blogArticle[$i]["blog.title"] = $row["title"];
		$blogArticle[$i]["blog.body"] = _fnc("strtrim", _fnc("clearBodyCodes", html_entity_decode($row["body"])), 50);
		$blogArticle[$i]["blog.id"] = $row["id"];
		$blogArticle[$i]["blog.userid"] = $row["user"];
		$blogArticle[$i]["blog.date"] = date($CONF["LOCALE_SHORT_DATE_TIME"], $row["date"]);
		$blogArticle[$i]["blog.views"] = $row["views"];
		$blogArticle[$i]["blog.comments"] = $row["comments"];
		$blogArticle[$i]["blog.mainpicture"] = _fnc("user", $row["user"], "mainpicture");
		$blogArticle[$i]["blog.username"] = _fnc("user", $row["user"], "username");
	
		$i++;
	}
	
	/*
		Pass the replacement array to the template 
		engine
	*/
	if (isset($blogArticle)) {

		$tpl->Zone("blogArticles","enabled");

		$tpl->Loop("blogArticles", $blogArticle);

		}

}
	/*
		Let's load the last 100 titles and IDs for
		the longer list. We will pick our first result
		at position 20 (since we already shown the
		20 first ones)
	*/
	$listSelect = myQ("SELECT `id`,`title` FROM `[x]blogs` ORDER BY `date` DESC LIMIT 100");
	
	/*
		And loop this
	*/
	$i=0;

	$blogArticlesList = false;

	if(myNum($listSelect) > 0 ){

	while ($listRow = myF($listSelect)) {
		
		$blogList[$i]["articlesList.id"] = $listRow["id"];
		$blogList[$i]["articlesList.title"] = _fnc("strtrim", $listRow["title"], 40);
		
		$i++;
	}
	
	/*
		if the array exist, we send its content
		to the loop engine
	*/
	if (isset($blogList)) {

	$tpl->Zone("blogArticlesList","enabled");

	$tpl->Loop("blogArticlesList", $blogList);

	}
	
	}


	/* 
		Show the write options if we're logged in
	*/
	if (me("id")) $tpl -> Zone("writeOptions", "enabled");

		/*
MOST READ BLOGS 
*/

$listSelect = myQ("SELECT `id`,`title`,`user`,`views` FROM `[x]blogs` ORDER BY `views` DESC LIMIT 5");

$i=0;

while ($listRow = myF($listSelect)) {

$MostReadblog[$i]["MostReadarticles.id"] = $listRow["id"];
$MostReadblog[$i]["MostReadarticles.title"] = _fnc("strtrim", $listRow["title"], 50);
$MostReadblog[$i]["MostReadarticles.user_id"] = $listRow["user"];
$MostReadblog[$i]["MostReadarticles.views"] = $listRow["views"];

$i++;
}

if (isset($MostReadblog)) $tpl->Loop("MostReadblogArticlesList", $MostReadblog);

/*
 MOST COMMENTED BLOGS 
*/

$listSelect = myQ("SELECT `id`,`title`,`user`,`comments` FROM `[x]blogs` ORDER BY `comments` DESC LIMIT 5");

$i=0;

while ($listRow = myF($listSelect)) {

$MostCommentedblog[$i]["MostCommentedarticles.id"] = $listRow["id"];
$MostCommentedblog[$i]["MostCommentedarticles.title"] = _fnc("strtrim", $listRow["title"], 50);
$MostCommentedblog[$i]["MostCommentedarticles.user_id"] = $listRow["user"];
$MostCommentedblog[$i]["MostCommentedarticles.comments"] = $listRow["comments"];

$i++;
}

if (isset($MostCommentedblog)) $tpl->Loop("MostCommentedblogArticlesList", $MostCommentedblog);
	
	$tpl -> CleanZones();
	$tpl -> Flush();
?>
	
		