<?php
!defined('M_P') && exit('Forbidden');

$tab = (int)GetGP('tab');

if ($tab == 1) {
	require_once(R_P.'require/showimg.php');
	$newWrite = array();
	$query = $db->query("SELECT wd.*,m.username,m.icon FROM pw_owritedata wd LEFT JOIN pw_members m ON wd.uid=m.uid WHERE wd.touid='' ORDER BY wd.id DESC LIMIT 15");
	while ($rt = $db->fetch_array($query)) {
		$rt['postdate'] = get_date($rt['postdate']);
		list($rt['icon']) = showfacedesign($rt['icon'],1);
		$newWrite[] = $rt;
	}
} elseif ($tab == 2) {
	$lastpid = $albumdb = $smphoto = array();
	$query = $db->query("SELECT aid,aname,photonum,ownerid,owner,lastphoto,lastpid,lasttime FROM pw_cnalbum WHERE atype='0' ORDER BY aid DESC LIMIT 10");
	while ($rt = $db->fetch_array($query)) {
		$rt['lasttime']		= get_date($rt['lasttime']);
		$rt['lastphoto']	= getphotourl($rt['lastphoto']);
		if ($rt['lastpid']) {
			$lastpid = array_merge($lastpid,explode(',',$rt['lastpid']));
		}
		$albumdb[] =  $rt;
	}
	if ($lastpid) {
		$query = $db->query('SELECT pid,aid,path FROM pw_cnphoto ORDER BY pid DESC LIMIT 6');
		while ($rt = $db->fetch_array($query)) {
			$rt['path']	= getphotourl($rt['path']);
			$smphoto[$rt['aid']][] = $rt;
		}
	}
} elseif ($tab == 3) {
	$newShares = array();
	$query = $db->query("SELECT * FROM pw_share WHERE ifhidden=0 ORDER BY id DESC LIMIT 20");
	while ($rt = $db->fetch_array($query)) {
		$rt['postdate'] = get_date($rt['postdate'],'m-d H:s');
		$temp = unserialize($rt['content']);
		if ($temp['video']) {
			$rt['host'] = $temp['video']['host'];
			$rt['hash'] = $temp['video']['hash'];
		}
		$rt['link']	= $temp['link'];
		$rt['title'] = "<a href=\"$temp[link]\" target=\"_blank\">".substrs($temp['link'],40)."</a>";
		$rt['descrip'] = $temp['descrip'];
		$rt['type_name']= getLangInfo('o',$rt['type'],false,1);
		if ($rt['uid']!=$winduid && $friends[$rt['uid']]) {
			$rt['face'] = $friends[$rt['uid']]['face'];
		}
		unset($rt['content']);
		$newShares[] = $rt;
	}
} elseif ($tab == 4) {
	require_once(R_P.'require/element.class.php');
	$element = new Element();

	$article = array();
	$result = $element->newSubject('new',0,30);
	foreach ($result as $val) {
		$article[] = array(
			'url' => $val['url'],
			'title' => substrs($val['title'],40),
			'author' => $val['addition']['author'],
			'authorid' => $val['addition']['authorid'],
			'postdate'	=> get_date($val['addition']['postdate']),
			'fid' => $val['addition']['fid'],
			'replies' => $val['addition']['replies'],
			'hits' => $val['addition']['hits']
		);
	}
} elseif ($tab == 5) {
	$reGroups = array();
	$query = $db->query("SELECT id,classid,cname,members,cnimg FROM pw_colonys ORDER BY members DESC LIMIT 15");
	while ($rt = $db->fetch_array($query)) {
		if ($rt['cnimg']) {
			list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]",'lf');
		} else {
			$rt['cnimg'] = $pwModeImg.'/nophoto.gif';
		}
		$reGroups[] = $rt;
	}
} elseif ($tab == 6) {
	require_once(R_P.'require/element.class.php');
	$element = new Element();

	$article = array();
	$result = $element->newReply('newReply',0,30);
	foreach ($result as $val) {
		$article[] = array(
			'url' => $val['url'],
			'title' => substrs($val['title'],40),
			'author' => $val['addition']['author'],
			'authorid' => $val['addition']['authorid'],
			'postdate'	=> get_date($val['addition']['postdate']),
			'fid' => $val['addition']['fid'],
			'replies' => $val['addition']['replies'],
			'hits' => $val['addition']['hits']
		);
	}
} else {
	require_once(R_P.'require/element.class.php');
	$element = new Element();

	$newPics = array();
	$result = $element->newPic('new',0,5);
	foreach ($result as $val) {
		$newPics[] = array(
			'url' => $val['url'],
			'title' => substrs($val['title'],30),
			'image' => $val['image']
		);
	}

	$newThreads = array();
	$result = $element->replySort('replysortday',0,5);
	foreach ($result as $val) {
		$newThreads[] = array(
			'url' => $val['url'],
			'title' => substrs($val['title'],30),
			'author' => $val['addition']['author'],
			'authorid' => $val['addition']['authorid'],
			'postdate'	=> get_date($val['addition']['postdate']),
			'fid' => $val['addition']['fid'],
			'replies' => $val['addition']['replies']
		);
	}

	$members = array();
	$result = $element->userSort('todaypost',0,6,true);
	foreach ($result as $val) {
		$members[] = array(
			'url' => $val['url'],
			'title'	=> $val['title'],
			'value'	=> $val['value'],
			'image' => $val['image']
		);
	}

	$reGroups = array();
	$query = $db->query("SELECT id,classid,cname,members,cnimg FROM pw_colonys ORDER BY members DESC LIMIT 5");
	while ($rt = $db->fetch_array($query)) {
		if ($rt['cnimg']) {
			list($rt['cnimg']) = geturl("cn_img/$rt[cnimg]",'lf');
		} else {
			$rt['cnimg'] = $pwModeImg.'/nophoto.gif';
		}
		$reGroups[] = $rt;
	}

	$newShares = array();
	$query = $db->query("SELECT * FROM pw_share WHERE ifhidden=0 ORDER BY id DESC LIMIT 10");
	while ($rt = $db->fetch_array($query)) {
		$rt['postdate'] = get_date($rt['postdate'],'m-d H:s');
		$temp = unserialize($rt['content']);
		if ($temp['video']) {
			$rt['host'] = $temp['video']['host'];
			$rt['hash'] = $temp['video']['hash'];
		}
		$rt['link']	= $temp['link'];
		$rt['title'] = "<a href=\"$temp[link]\" target=\"_blank\">".substrs($temp['link'],40)."</a>";
		$rt['descrip'] = $temp['descrip'];
		$rt['type_name']= getLangInfo('o',$rt['type'],false,1);
		if ($rt['uid']!=$winduid && $friends[$rt['uid']]) {
			$rt['face'] = $friends[$rt['uid']]['face'];
		}
		unset($rt['content']);
		$newShares[] = $rt;
	}
}
require_once(R_P.'require/header.php');
require_once PrintEot('m_browse');footer();
?>