1 <?php
2 
3 /*
4 	[UCenter] (C)2001-2099 Comsenz Inc.
5 	This is NOT a freeware, use is subject to license terms
6 
7 	$Id: client.php 1179 2014-11-03 07:11:25Z hypowang $
8 */
9 
10 if(!defined('UC_API')) {
11 	exit('Access denied');
12 }
13 
14 error_reporting(0);
15 
16 define('IN_UC', TRUE);
17 define('UC_CLIENT_VERSION', '1.6.0');
18 define('UC_CLIENT_RELEASE', '20141101');
19 define('UC_ROOT', substr(__FILE__, 0, -10));
20 define('UC_DATADIR', UC_ROOT.'./data/');
21 define('UC_DATAURL', UC_API.'/data');
22 define('UC_API_FUNC', UC_CONNECT == 'mysql' ? 'uc_api_mysql' : 'uc_api_post');
23 $GLOBALS['uc_controls'] = array();
24 
25 function uc_addslashes($string, $force = 0, $strip = FALSE) {
26 	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
27 	if(!MAGIC_QUOTES_GPC || $force) {
28 		if(is_array($string)) {
29 			foreach($string as $key => $val) {
30 				$string[$key] = uc_addslashes($val, $force, $strip);
31 			}
32 		} else {
33 			$string = addslashes($strip ? stripslashes($string) : $string);
34 		}
35 	}
36 	return $string;
37 }
38 
39 if(!function_exists('daddslashes')) {
40 	function daddslashes($string, $force = 0) {
41 		return uc_addslashes($string, $force);
42 	}
43 }
44 
45 
46 if(!function_exists('dhtmlspecialchars')) {
47 	function dhtmlspecialchars($string, $flags = null) {
48 		if(is_array($string)) {
49 			foreach($string as $key => $val) {
50 				$string[$key] = dhtmlspecialchars($val, $flags);
51 			}
52 		} else {
53 			if($flags === null) {
54 				$string = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string);
55 				if(strpos($string, '&amp;#') !== false) {
56 					$string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1', $string);
57 				}
58 			} else {
59 				if(PHP_VERSION < '5.4.0') {
60 					$string = htmlspecialchars($string, $flags);
61 				} else {
62 					if(strtolower(CHARSET) == 'utf-8') {
63 						$charset = 'UTF-8';
64 					} else {
65 						$charset = 'ISO-8859-1';
66 					}
67 					$string = htmlspecialchars($string, $flags, $charset);
68 				}
69 			}
70 		}
71 		return $string;
72 	}
73 }
74 if(!function_exists('fsocketopen')) {
75 	function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) {
76 		$fp = '';
77 		if(function_exists('fsockopen')) {
78 			$fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
79 		} elseif(function_exists('pfsockopen')) {
80 			$fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
81 		} elseif(function_exists('stream_socket_client')) {
82 			$fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
83 		}
84 		return $fp;
85 	}
86 }
87 
88 function uc_stripslashes($string) {
89 	!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
90 	if(MAGIC_QUOTES_GPC) {
91 		return stripslashes($string);
92 	} else {
93 		return $string;
94 	}
95 }
96 
97 function uc_api_post($module, $action, $arg = array()) {
98 	$s = $sep = '';
99 	foreach($arg as $k => $v) {
100 		$k = urlencode($k);
101 		if(is_array($v)) {
102 			$s2 = $sep2 = '';
103 			foreach($v as $k2 => $v2) {
104 				$k2 = urlencode($k2);
105 				$s2 .= "$sep2{$k}[$k2]=".urlencode(uc_stripslashes($v2));
106 				$sep2 = '&';
107 			}
108 			$s .= $sep.$s2;
109 		} else {
110 			$s .= "$sep$k=".urlencode(uc_stripslashes($v));
111 		}
112 		$sep = '&';
113 	}
114 	$postdata = uc_api_requestdata($module, $action, $s);
115 	return uc_fopen2(UC_API.'/index.php', 500000, $postdata, '', TRUE, UC_IP, 20);
116 }
117 
118 function uc_api_requestdata($module, $action, $arg='', $extra='') {
119 	$input = uc_api_input($arg);
120 	$post = "m=$module&a=$action&inajax=2&release=".UC_CLIENT_RELEASE."&input=$input&appid=".UC_APPID.$extra;
121 	return $post;
122 }
123 
124 function uc_api_url($module, $action, $arg='', $extra='') {
125 	$url = UC_API.'/index.php?'.uc_api_requestdata($module, $action, $arg, $extra);
126 	return $url;
127 }
128 
129 function uc_api_input($data) {
130 	$s = urlencode(uc_authcode($data.'&agent='.md5($_SERVER['HTTP_USER_AGENT'])."&time=".time(), 'ENCODE', UC_KEY));
131 	return $s;
132 }
133 
134 function uc_api_mysql($model, $action, $args=array()) {
135 	global $uc_controls;
136 	if(empty($uc_controls[$model])) {
137 		if(function_exists("mysql_connect")) {
138 			include_once UC_ROOT.'./lib/db.class.php';
139 		} else {
140 			include_once UC_ROOT.'./lib/dbi.class.php';
141 		}
142 		include_once UC_ROOT.'./model/base.php';
143 		include_once UC_ROOT."./control/$model.php";
144 		eval("\$uc_controls['$model'] = new {$model}control();");
145 	}
146 	if($action{0} != '_') {
147 		$args = uc_addslashes($args, 1, TRUE);
148 		$action = 'on'.$action;
149 		$uc_controls[$model]->input = $args;
150 		return $uc_controls[$model]->$action($args);
151 	} else {
152 		return '';
153 	}
154 }
155 
156 function uc_serialize($arr, $htmlon = 0) {
157 	include_once UC_ROOT.'./lib/xml.class.php';
158 	return xml_serialize($arr, $htmlon);
159 }
160 
161 function uc_unserialize($s) {
162 	include_once UC_ROOT.'./lib/xml.class.php';
163 	return xml_unserialize($s);
164 }
165 
166 function uc_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
167 
168 	$ckey_length = 4;
169 
170 	$key = md5($key ? $key : UC_KEY);
171 	$keya = md5(substr($key, 0, 16));
172 	$keyb = md5(substr($key, 16, 16));
173 	$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
174 
175 	$cryptkey = $keya.md5($keya.$keyc);
176 	$key_length = strlen($cryptkey);
177 
178 	$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
179 	$string_length = strlen($string);
180 
181 	$result = '';
182 	$box = range(0, 255);
183 
184 	$rndkey = array();
185 	for($i = 0; $i <= 255; $i++) {
186 		$rndkey[$i] = ord($cryptkey[$i % $key_length]);
187 	}
188 
189 	for($j = $i = 0; $i < 256; $i++) {
190 		$j = ($j + $box[$i] + $rndkey[$i]) % 256;
191 		$tmp = $box[$i];
192 		$box[$i] = $box[$j];
193 		$box[$j] = $tmp;
194 	}
195 
196 	for($a = $j = $i = 0; $i < $string_length; $i++) {
197 		$a = ($a + 1) % 256;
198 		$j = ($j + $box[$a]) % 256;
199 		$tmp = $box[$a];
200 		$box[$a] = $box[$j];
201 		$box[$j] = $tmp;
202 		$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
203 	}
204 
205 	if($operation == 'DECODE') {
206 		if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
207 			return substr($result, 26);
208 		} else {
209 			return '';
210 		}
211 	} else {
212 		return $keyc.str_replace('=', '', base64_encode($result));
213 	}
214 }
215 
216 function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
217 	$__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
218 	if($__times__ > 2) {
219 		return '';
220 	}
221 	$url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
222 	return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block);
223 }
224 
225 function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
226 	$return = '';
227 	$matches = parse_url($url);
228 	!isset($matches['scheme']) && $matches['scheme'] = '';
229 	!isset($matches['host']) && $matches['host'] = '';
230 	!isset($matches['path']) && $matches['path'] = '';
231 	!isset($matches['query']) && $matches['query'] = '';
232 	!isset($matches['port']) && $matches['port'] = '';
233 	$scheme = $matches['scheme'];
234 	$host = $matches['host'];
235 	$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
236 	$port = !empty($matches['port']) ? $matches['port'] : 80;
237 	if($post) {
238 		$out = "POST $path HTTP/1.0\r\n";
239 		$header = "Accept: */*\r\n";
240 		$header .= "Accept-Language: zh-cn\r\n";
241 		$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
242 		$header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
243 		$header .= "Host: $host\r\n";
244 		$header .= 'Content-Length: '.strlen($post)."\r\n";
245 		$header .= "Connection: Close\r\n";
246 		$header .= "Cache-Control: no-cache\r\n";
247 		$header .= "Cookie: $cookie\r\n\r\n";
248 		$out .= $header.$post;
249 	} else {
250 		$out = "GET $path HTTP/1.0\r\n";
251 		$header = "Accept: */*\r\n";
252 		$header .= "Accept-Language: zh-cn\r\n";
253 		$header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
254 		$header .= "Host: $host\r\n";
255 		$header .= "Connection: Close\r\n";
256 		$header .= "Cookie: $cookie\r\n\r\n";
257 		$out .= $header;
258 	}
259 
260 	$fpflag = 0;
261 	if(!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout)) {
262 		$context = array(
263 			'http' => array(
264 				'method' => $post ? 'POST' : 'GET',
265 				'header' => $header,
266 				'content' => $post,
267 				'timeout' => $timeout,
268 			),
269 		);
270 		$context = stream_context_create($context);
271 		$fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context);
272 		$fpflag = 1;
273 	}
274 
275 	if(!$fp) {
276 		return '';
277 	} else {
278 		stream_set_blocking($fp, $block);
279 		stream_set_timeout($fp, $timeout);
280 		@fwrite($fp, $out);
281 		$status = stream_get_meta_data($fp);
282 		if(!$status['timed_out']) {
283 			while (!feof($fp) && !$fpflag) {
284 				if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
285 					break;
286 				}
287 			}
288 
289 			$stop = false;
290 			while(!feof($fp) && !$stop) {
291 				$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
292 				$return .= $data;
293 				if($limit) {
294 					$limit -= strlen($data);
295 					$stop = $limit <= 0;
296 				}
297 			}
298 		}
299 		@fclose($fp);
300 		return $return;
301 	}
302 }
303 
304 function uc_app_ls() {
305 	$return = call_user_func(UC_API_FUNC, 'app', 'ls', array());
306 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
307 }
308 
309 function uc_feed_add($icon, $uid, $username, $title_template='', $title_data='', $body_template='', $body_data='', $body_general='', $target_ids='', $images = array()) {
310 	return call_user_func(UC_API_FUNC, 'feed', 'add',
311 		array(  'icon'=>$icon,
312 			'appid'=>UC_APPID,
313 			'uid'=>$uid,
314 			'username'=>$username,
315 			'title_template'=>$title_template,
316 			'title_data'=>$title_data,
317 			'body_template'=>$body_template,
318 			'body_data'=>$body_data,
319 			'body_general'=>$body_general,
320 			'target_ids'=>$target_ids,
321 			'image_1'=>$images[0]['url'],
322 			'image_1_link'=>$images[0]['link'],
323 			'image_2'=>$images[1]['url'],
324 			'image_2_link'=>$images[1]['link'],
325 			'image_3'=>$images[2]['url'],
326 			'image_3_link'=>$images[2]['link'],
327 			'image_4'=>$images[3]['url'],
328 			'image_4_link'=>$images[3]['link']
329 		)
330 	);
331 }
332 
333 function uc_feed_get($limit = 100, $delete = TRUE) {
334 	$return = call_user_func(UC_API_FUNC, 'feed', 'get', array('limit'=>$limit, 'delete'=>$delete));
335 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
336 }
337 
338 function uc_friend_add($uid, $friendid, $comment='') {
339 	return call_user_func(UC_API_FUNC, 'friend', 'add', array('uid'=>$uid, 'friendid'=>$friendid, 'comment'=>$comment));
340 }
341 
342 function uc_friend_delete($uid, $friendids) {
343 	return call_user_func(UC_API_FUNC, 'friend', 'delete', array('uid'=>$uid, 'friendids'=>$friendids));
344 }
345 
346 function uc_friend_totalnum($uid, $direction = 0) {
347 	return call_user_func(UC_API_FUNC, 'friend', 'totalnum', array('uid'=>$uid, 'direction'=>$direction));
348 }
349 
350 function uc_friend_ls($uid, $page = 1, $pagesize = 10, $totalnum = 10, $direction = 0) {
351 	$return = call_user_func(UC_API_FUNC, 'friend', 'ls', array('uid'=>$uid, 'page'=>$page, 'pagesize'=>$pagesize, 'totalnum'=>$totalnum, 'direction'=>$direction));
352 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
353 }
354 
355 function uc_user_register($username, $password, $email, $questionid = '', $answer = '', $regip = '') {
356 	return call_user_func(UC_API_FUNC, 'user', 'register', array('username'=>$username, 'password'=>$password, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer, 'regip' => $regip));
357 }
358 
359 function uc_user_login($username, $password, $isuid = 0, $checkques = 0, $questionid = '', $answer = '', $ip = '') {
360 	$isuid = intval($isuid);
361 	$return = call_user_func(UC_API_FUNC, 'user', 'login', array('username'=>$username, 'password'=>$password, 'isuid'=>$isuid, 'checkques'=>$checkques, 'questionid'=>$questionid, 'answer'=>$answer, 'ip' => $ip));
362 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
363 }
364 
365 function uc_user_synlogin($uid) {
366 	$uid = intval($uid);
367 	if(@include UC_ROOT.'./data/cache/apps.php') {
368 		if(count($_CACHE['apps']) > 1) {
369 			$return = uc_api_post('user', 'synlogin', array('uid'=>$uid));
370 		} else {
371 			$return = '';
372 		}
373 	}
374 	return $return;
375 }
376 
377 function uc_user_synlogout() {
378 	if(@include UC_ROOT.'./data/cache/apps.php') {
379 		if(count($_CACHE['apps']) > 1) {
380 			$return = uc_api_post('user', 'synlogout', array());
381 		} else {
382 			$return = '';
383 		}
384 	}
385 	return $return;
386 }
387 
388 function uc_user_edit($username, $oldpw, $newpw, $email, $ignoreoldpw = 0, $questionid = '', $answer = '') {
389 	return call_user_func(UC_API_FUNC, 'user', 'edit', array('username'=>$username, 'oldpw'=>$oldpw, 'newpw'=>$newpw, 'email'=>$email, 'ignoreoldpw'=>$ignoreoldpw, 'questionid'=>$questionid, 'answer'=>$answer));
390 }
391 
392 function uc_user_delete($uid) {
393 	return call_user_func(UC_API_FUNC, 'user', 'delete', array('uid'=>$uid));
394 }
395 
396 function uc_user_deleteavatar($uid) {
397 	uc_api_post('user', 'deleteavatar', array('uid'=>$uid));
398 }
399 
400 function uc_user_checkname($username) {
401 	return call_user_func(UC_API_FUNC, 'user', 'check_username', array('username'=>$username));
402 }
403 
404 function uc_user_checkemail($email) {
405 	return call_user_func(UC_API_FUNC, 'user', 'check_email', array('email'=>$email));
406 }
407 
408 function uc_user_addprotected($username, $admin='') {
409 	return call_user_func(UC_API_FUNC, 'user', 'addprotected', array('username'=>$username, 'admin'=>$admin));
410 }
411 
412 function uc_user_deleteprotected($username) {
413 	return call_user_func(UC_API_FUNC, 'user', 'deleteprotected', array('username'=>$username));
414 }
415 
416 function uc_user_getprotected() {
417 	$return = call_user_func(UC_API_FUNC, 'user', 'getprotected', array('1'=>1));
418 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
419 }
420 
421 function uc_get_user($username, $isuid=0) {
422 	$return = call_user_func(UC_API_FUNC, 'user', 'get_user', array('username'=>$username, 'isuid'=>$isuid));
423 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
424 }
425 
426 function uc_user_merge($oldusername, $newusername, $uid, $password, $email) {
427 	return call_user_func(UC_API_FUNC, 'user', 'merge', array('oldusername'=>$oldusername, 'newusername'=>$newusername, 'uid'=>$uid, 'password'=>$password, 'email'=>$email));
428 }
429 
430 function uc_user_merge_remove($username) {
431 	return call_user_func(UC_API_FUNC, 'user', 'merge_remove', array('username'=>$username));
432 }
433 
434 function uc_user_getcredit($appid, $uid, $credit) {
435 	return uc_api_post('user', 'getcredit', array('appid'=>$appid, 'uid'=>$uid, 'credit'=>$credit));
436 }
437 
438 
439 function uc_user_logincheck($username, $ip) {
440 	return call_user_func(UC_API_FUNC, 'user', 'logincheck', array('username' => $username, 'ip' => $ip));
441 }
442 
443 function uc_pm_location($uid, $newpm = 0) {
444 	$apiurl = uc_api_url('pm_client', 'ls', "uid=$uid", ($newpm ? '&folder=newbox' : ''));
445 	@header("Expires: 0");
446 	@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
447 	@header("Pragma: no-cache");
448 	@header("location: $apiurl");
449 }
450 
451 function uc_pm_checknew($uid, $more = 0) {
452 	$return = call_user_func(UC_API_FUNC, 'pm', 'check_newpm', array('uid'=>$uid, 'more'=>$more));
453 	return (!$more || UC_CONNECT == 'mysql') ? $return : uc_unserialize($return);
454 }
455 
456 function uc_pm_send($fromuid, $msgto, $subject, $message, $instantly = 1, $replypmid = 0, $isusername = 0, $type = 0) {
457 	if($instantly) {
458 		$replypmid = @is_numeric($replypmid) ? $replypmid : 0;
459 		return call_user_func(UC_API_FUNC, 'pm', 'sendpm', array('fromuid'=>$fromuid, 'msgto'=>$msgto, 'subject'=>$subject, 'message'=>$message, 'replypmid'=>$replypmid, 'isusername'=>$isusername, 'type' => $type));
460 	} else {
461 		$fromuid = intval($fromuid);
462 		$subject = rawurlencode($subject);
463 		$msgto = rawurlencode($msgto);
464 		$message = rawurlencode($message);
465 		$replypmid = @is_numeric($replypmid) ? $replypmid : 0;
466 		$replyadd = $replypmid ? "&pmid=$replypmid&do=reply" : '';
467 		$apiurl = uc_api_url('pm_client', 'send', "uid=$fromuid", "&msgto=$msgto&subject=$subject&message=$message$replyadd");
468 		@header("Expires: 0");
469 		@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
470 		@header("Pragma: no-cache");
471 		@header("location: ".$apiurl);
472 	}
473 }
474 
475 function uc_pm_delete($uid, $folder, $pmids) {
476 	return call_user_func(UC_API_FUNC, 'pm', 'delete', array('uid'=>$uid, 'pmids'=>$pmids));
477 }
478 
479 function uc_pm_deleteuser($uid, $touids) {
480 	return call_user_func(UC_API_FUNC, 'pm', 'deleteuser', array('uid'=>$uid, 'touids'=>$touids));
481 }
482 
483 function uc_pm_deletechat($uid, $plids, $type = 0) {
484 	return call_user_func(UC_API_FUNC, 'pm', 'deletechat', array('uid'=>$uid, 'plids'=>$plids, 'type'=>$type));
485 }
486 
487 function uc_pm_readstatus($uid, $uids, $plids = array(), $status = 0) {
488 	return call_user_func(UC_API_FUNC, 'pm', 'readstatus', array('uid'=>$uid, 'uids'=>$uids, 'plids'=>$plids, 'status'=>$status));
489 }
490 
491 function uc_pm_list($uid, $page = 1, $pagesize = 10, $folder = 'inbox', $filter = 'newpm', $msglen = 0) {
492 	$uid = intval($uid);
493 	$page = intval($page);
494 	$pagesize = intval($pagesize);
495 	$return = call_user_func(UC_API_FUNC, 'pm', 'ls', array('uid'=>$uid, 'page'=>$page, 'pagesize'=>$pagesize, 'filter'=>$filter, 'msglen'=>$msglen));
496 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
497 }
498 
499 function uc_pm_ignore($uid) {
500 	$uid = intval($uid);
501 	return call_user_func(UC_API_FUNC, 'pm', 'ignore', array('uid'=>$uid));
502 }
503 
504 function uc_pm_view($uid, $pmid = 0, $touid = 0, $daterange = 1, $page = 0, $pagesize = 10, $type = 0, $isplid = 0) {
505 	$uid = intval($uid);
506 	$touid = intval($touid);
507 	$page = intval($page);
508 	$pagesize = intval($pagesize);
509 	$pmid = @is_numeric($pmid) ? $pmid : 0;
510 	$return = call_user_func(UC_API_FUNC, 'pm', 'view', array('uid'=>$uid, 'pmid'=>$pmid, 'touid'=>$touid, 'daterange'=>$daterange, 'page' => $page, 'pagesize' => $pagesize, 'type'=>$type, 'isplid'=>$isplid));
511 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
512 }
513 
514 function uc_pm_view_num($uid, $touid, $isplid) {
515 	$uid = intval($uid);
516 	$touid = intval($touid);
517 	$isplid = intval($isplid);
518 	return call_user_func(UC_API_FUNC, 'pm', 'viewnum', array('uid' => $uid, 'touid' => $touid, 'isplid' => $isplid));
519 }
520 
521 function uc_pm_viewnode($uid, $type, $pmid) {
522 	$uid = intval($uid);
523 	$type = intval($type);
524 	$pmid = @is_numeric($pmid) ? $pmid : 0;
525 	$return = call_user_func(UC_API_FUNC, 'pm', 'viewnode', array('uid'=>$uid, 'type'=>$type, 'pmid'=>$pmid));
526 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
527 }
528 
529 function uc_pm_chatpmmemberlist($uid, $plid = 0) {
530 	$uid = intval($uid);
531 	$plid = intval($plid);
532 	$return = call_user_func(UC_API_FUNC, 'pm', 'chatpmmemberlist', array('uid'=>$uid, 'plid'=>$plid));
533 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
534 }
535 
536 function uc_pm_kickchatpm($plid, $uid, $touid) {
537 	$uid = intval($uid);
538 	$plid = intval($plid);
539 	$touid = intval($touid);
540 	return call_user_func(UC_API_FUNC, 'pm', 'kickchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
541 }
542 
543 function uc_pm_appendchatpm($plid, $uid, $touid) {
544 	$uid = intval($uid);
545 	$plid = intval($plid);
546 	$touid = intval($touid);
547 	return call_user_func(UC_API_FUNC, 'pm', 'appendchatpm', array('uid'=>$uid, 'plid'=>$plid, 'touid'=>$touid));
548 }
549 
550 function uc_pm_blackls_get($uid) {
551 	$uid = intval($uid);
552 	return call_user_func(UC_API_FUNC, 'pm', 'blackls_get', array('uid'=>$uid));
553 }
554 
555 function uc_pm_blackls_set($uid, $blackls) {
556 	$uid = intval($uid);
557 	return call_user_func(UC_API_FUNC, 'pm', 'blackls_set', array('uid'=>$uid, 'blackls'=>$blackls));
558 }
559 
560 function uc_pm_blackls_add($uid, $username) {
561 	$uid = intval($uid);
562 	return call_user_func(UC_API_FUNC, 'pm', 'blackls_add', array('uid'=>$uid, 'username'=>$username));
563 }
564 
565 function uc_pm_blackls_delete($uid, $username) {
566 	$uid = intval($uid);
567 	return call_user_func(UC_API_FUNC, 'pm', 'blackls_delete', array('uid'=>$uid, 'username'=>$username));
568 }
569 
570 function uc_domain_ls() {
571 	$return = call_user_func(UC_API_FUNC, 'domain', 'ls', array('1'=>1));
572 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
573 }
574 
575 function uc_credit_exchange_request($uid, $from, $to, $toappid, $amount) {
576 	$uid = intval($uid);
577 	$from = intval($from);
578 	$toappid = intval($toappid);
579 	$to = intval($to);
580 	$amount = intval($amount);
581 	return uc_api_post('credit', 'request', array('uid'=>$uid, 'from'=>$from, 'to'=>$to, 'toappid'=>$toappid, 'amount'=>$amount));
582 }
583 
584 function uc_tag_get($tagname, $nums = 0) {
585 	$return = call_user_func(UC_API_FUNC, 'tag', 'gettag', array('tagname'=>$tagname, 'nums'=>$nums));
586 	return UC_CONNECT == 'mysql' ? $return : uc_unserialize($return);
587 }
588 
589 function uc_avatar($uid, $type = 'virtual', $returnhtml = 1) {
590 	$uid = intval($uid);
591 	$uc_input = uc_api_input("uid=$uid");
592 	$uc_avatarflash = UC_API.'/images/camera.swf?inajax=1&appid='.UC_APPID.'&input='.$uc_input.'&agent='.md5($_SERVER['HTTP_USER_AGENT']).'&ucapi='.urlencode(str_replace('http://', '', UC_API)).'&avatartype='.$type.'&uploadSize=2048';
593 	if($returnhtml) {
594 		return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="450" height="253" id="mycamera" align="middle">
595 			<param name="allowScriptAccess" value="always" />
596 			<param name="scale" value="exactfit" />
597 			<param name="wmode" value="transparent" />
598 			<param name="quality" value="high" />
599 			<param name="bgcolor" value="#ffffff" />
600 			<param name="movie" value="'.$uc_avatarflash.'" />
601 			<param name="menu" value="false" />
602 			<embed src="'.$uc_avatarflash.'" quality="high" bgcolor="#ffffff" width="450" height="253" name="mycamera" align="middle" allowScriptAccess="always" allowFullScreen="false" scale="exactfit"  wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
603 		</object>';
604 	} else {
605 		return array(
606 			'width', '450',
607 			'height', '253',
608 			'scale', 'exactfit',
609 			'src', $uc_avatarflash,
610 			'id', 'mycamera',
611 			'name', 'mycamera',
612 			'quality','high',
613 			'bgcolor','#ffffff',
614 			'menu', 'false',
615 			'swLiveConnect', 'true',
616 			'allowScriptAccess', 'always'
617 		);
618 	}
619 }
620 
621 function uc_mail_queue($uids, $emails, $subject, $message, $frommail = '', $charset = 'gbk', $htmlon = FALSE, $level = 1) {
622 	return call_user_func(UC_API_FUNC, 'mail', 'add', array('uids' => $uids, 'emails' => $emails, 'subject' => $subject, 'message' => $message, 'frommail' => $frommail, 'charset' => $charset, 'htmlon' => $htmlon, 'level' => $level));
623 }
624 
625 function uc_check_avatar($uid, $size = 'middle', $type = 'virtual') {
626 	$url = UC_API."/avatar.php?uid=$uid&size=$size&type=$type&check_file_exists=1";
627 	$res = uc_fopen2($url, 500000, '', '', TRUE, UC_IP, 20);
628 	if($res == 1) {
629 		return 1;
630 	} else {
631 		return 0;
632 	}
633 }
634 
635 function uc_check_version() {
636 	$return = uc_api_post('version', 'check', array());
637 	$data = uc_unserialize($return);
638 	return is_array($data) ? $data : $return;
639 }
640 
641 ?>