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

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

InitGP(array('see'),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,'',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';
} 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;
	}
}

$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'];
		$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']);
		$shares[] = $rt;
	}
	$pages = numofpage($count,$page,$numofpage,$thisbase);
}
require_once(R_P.'require/header.php');
require_once PrintEot('m_share');
footer();
?>