<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'tab_blog'); // change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array();
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_forumdisplay.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################


$tab_options['title_maxchars'] = '50';


echo '<ol class="floatcontainer" id="forums">
	<li id="cat1" class="forumbit_nopost L1">
		<div class="forumhead foruminfo L1 collapse">
			<h2>
				<span class="forumtitle"><a href="forumdisplay.php?1-Main-Category">Main Category</a></span>
				<span class="forumlastpost">Blogger/Date</span>
			</h2>
		</div>
	
		<ol class="childforum" id="c_cat1">';

$latestblogs = $db->query(" 
    SELECT blog.blogid, blog.firstblogtextid, blog.title, blog.username, blog.dateline, blog.userid, blog.views, blog_text.pagetext as preview
    FROM " . TABLE_PREFIX . "blog AS blog
    LEFT JOIN " . TABLE_PREFIX . "blog_text AS blog_text ON (blog_text.blogid = blog.blogid)
    WHERE blog.state='visible' and blog.pending=0
    GROUP BY blog.blogid 
    ORDER BY blog.dateline DESC 
    LIMIT 10 
"); 

while ($showblogs=$db->fetch_array($latestblogs)) 
{ 
		
	// Trim title
   	if (strlen($showblogs['title']) > $tab_options['title_maxchars'] AND $tab_options['title_maxchars'])
   	{
		$showblogs['title'] = fetch_trimmed_title($showblogs['title'], $tab_options['title_maxchars']);
   	}

	// Process array
	$showblogs = process_thread_array(
		$showblogs,
		$mod_options['portal_threads_showicon']
	);

	$blog_userid = $showblogs['userid'];
    $blogid = $showblogs['blogid'];
    $blog_title = $showblogs['title'];
    $blog_views = $showblogs['views'];
    $blog_username = $showblogs['username'];
    $blog_dateline = vbdate($vbulletin->options['dateformat'], $showblogs['dateline']);
    $blog_preview = $showblogs['preview'];

	echo '<li class="forumbit_post L2" id="forum2">
	<div class="forumrow table">
		<div class="foruminfo td">
			<img alt="" id="forum_statusicon_2" class="forumicon" src="images/statusicon/forum_old-48.png">
			<div class="forumdata">
				<div class="datacontainer">
					<div class="titleline">
						<h2 class="forumtitle"><a href="blog.php?b=' . $blogid . '"><b>' . $blog_title . '</b></a></h2>
					</div>
					<p class="forumdescription">' . $blog_preview . '<span class="smallfont">&nbsp;<a href="blog.php?b=' . $blogid . '"><b>more</b></a></span></p>
				</div>
			</div>
		</div>
        
		<h4 class="nocss_label">Forum Actions:</h4>
		<ul class="forumactionlinks td"> </ul>
        <h4 class="nocss_label">Forum Statistics:</h4>
		<ul class="forumstats td">
			<li>Views: ' . $blog_views . '</li>
			<li>Comments: ' . $blog_views . '</li>
		</ul>
		<div class="forumlastpost td">
			<h4 class="lastpostlabel">Last Post:</h4>
			<div>
				<div class="lastpostby">by 
					<div class="popupmenu memberaction">
						<a href="blog.php?u=' . $blog_userid . '"><strong>' . $blog_username . '</strong></a>
					</div>
 				</div>
				<p class="lastpostdate">' . $blog_dateline . '</p>
			</div>
		</div>
	</div>
</li>';

}

echo '</ol></li></ol>';

$db->free_result($latestblogs);
unset($showblogs);

?>