<?php
!defined('M_P') && exit('Forbidden');
!$winduid && Showmsg('not_login');

require_once(R_P.'require/showimg.php');

InitGP(array('see','type'),null,1);
$u = (int)GetGP('u');
!$u && $u = $winduid;
$thisbase = $basename."q=share&";

$where = '';
if ($see == 'friend') {
	list($faceimg) = showfacedesign($winddb['icon'],1);
	if ($friends = getFriends($winduid,0,0,false,1)) {
		$uids = array_keys($friends);
		$where .= 'uid IN('.pwImplode($uids).') AND ifhidden=0';
	} else {
		require_once(R_P.'require/header.php');
		require_once PrintEot('m_share');
		footer();
	}
	$username = $windid;
	$thisbase .= "see=$see&";
} elseif ($see == 'favor') {
	list($faceimg) = showfacedesign($winddb['icon'],1);
	$username = $windid;
	$where .= 'uid='.pwEscape($winduid).' AND ifhidden=1';
	$thisbase .= "see=$see&";
} else {
	if ($u!=$winduid) {
		$friend = getOneFriend($u);
		if ($friend) {
			$where .= 'uid='.pwEscape($u).' AND ifhidden=0';
			$faceimg = $friend['face'];
			$username = $friend['username'];
		} else {
			Showmsg('mode_o_not_friend');
		}
		$thisbase .= "u=$u&";
	} else {
		list($faceimg) = showfacedesign($winddb['icon'],1);
		$where .= 'uid='.pwEscape($winduid).' AND ifhidden=0';
		$username = $windid;
	}
}
if ($type && in_array($type,array('web','user','photo','album','group','video','music','flash'))) {
	$where .= ($where=='' ? 'type='.pwEscape($type) : ' AND type='.pwEscape($type));
}

$shares = array();
$count = $db->get_value("SELECT count(*) as count FROM pw_share WHERE $where");
if ($count) {
	$perpage = 10;
	$page = (int)GetGP('page');
	$page<1 && $page = 1;
	$start = ($page-1)*$perpage;
	$numofpage = ceil($count/$perpage);

	$rs = $db->query("SELECT * FROM pw_share WHERE $where ORDER BY id DESC ".pwLimit($start,$perpage));
	while ($rt = $db->fetch_array($rs)) {
		$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'];
		if ($rt['type']=='user') {
			$temp['link']	= $temp['user']['username'];
			$rt['image']	= $temp['user']['image'];
			$rt['title']= "<a href=\"$rt[link]\" target=\"_blank\">".$temp['user']['username']."</a>";
		} elseif ($rt['type']=='photo') {
			$belong	= getLangInfo('o','photo_belong',false,1);
			$rt['image']	= $temp['photo']['image'];
			$temp_uid	= $temp['photo']['uid'];
			$rt['title']= $belong."<a href=\"mode.php?m=o&q=user&u=$temp_uid\" target=\"_blank\">".$temp['photo']['username']."</a>";
		} elseif ($rt['type']=='album') {
			$belong	= getLangInfo('o','photo_belong',false,1);
			$rt['image']	= $temp['album']['image'];
			$temp_uid	= $temp['album']['uid'];
			$rt['title']= $belong."<a href=\"mode.php?m=o&q=user&u=$temp_uid\" target=\"_blank\">".$temp['album']['username']."</a>";
		} elseif ($rt['type']=='group') {
			$rt['image']	= $temp['group']['image'];
			$rt['title']= "<a href=\"$rt[link]\" target=\"_blank\">".$temp['group']['name']."</a>";
		} else {
			$rt['title']= "<a href=\"$rt[link]\" target=\"_blank\">".substrs($rt['link'],40)."</a>";
		}
		$rt['descrip']	= $temp['descrip'];
		if ($rt['ifhidden']) {
			$rt['type_name']	= getLangInfo('o',$rt['type'].'_self',false,1);
		} else {
			$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']);
		$shares[] = $rt;
	}
	$pages = numofpage($count,$page,$numofpage,$thisbase);
}
require_once(R_P.'require/header.php');
require_once PrintEot('m_share');
footer();
?>