client.php 27 KB

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