pm.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: pm.php 1067 2011-03-08 10:06:51Z svn_project_zhangjie $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. define('PRIVATEPMTHREADLIMIT_ERROR', -1);
  9. define('PMFLOODCTRL_ERROR', -2);
  10. define('PMMSGTONOTFRIEND', -3);
  11. define('PMSENDREGDAYS', -4);
  12. define('CHATPMTHREADLIMIT_ERROR', -5);
  13. define('CHATPMMEMBERLIMIT_ERROR', -7);
  14. class pmcontrol extends base
  15. {
  16. function __construct()
  17. {
  18. $this->pmcontrol();
  19. }
  20. function pmcontrol()
  21. {
  22. parent::__construct();
  23. $this->load('user');
  24. $this->load('pm');
  25. }
  26. function oncheck_newpm()
  27. {
  28. $this->init_input();
  29. $uid = intval($this->input('uid'));
  30. $more = intval($this->input('more'));
  31. if (!$_ENV['pm']->isnewpm($uid) && !$more)
  32. {
  33. return 0;
  34. }
  35. $newprvpm = $_ENV['pm']->getpmnum($uid, 1, 1);
  36. $newchatpm = $_ENV['pm']->getpmnum($uid, 2, 1);
  37. $newpm = $newprvpm + $newchatpm;
  38. if ($more == 0)
  39. {
  40. return $newpm;
  41. }
  42. elseif ($more == 1)
  43. {
  44. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm);
  45. }
  46. elseif ($more == 2 || $more == 3)
  47. {
  48. if ($more == 2)
  49. {
  50. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm);
  51. }
  52. else
  53. {
  54. $lastpm = $_ENV['pm']->lastpm($uid);
  55. require_once UC_ROOT . 'lib/uccode.class.php';
  56. $this->uccode = new uccode();
  57. $lastpm['lastsummary'] = $this->uccode->complie($lastpm['lastsummary']);
  58. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm, 'lastdate' => $lastpm['lastdateline'], 'lastmsgfromid' => $lastpm['lastauthorid'], 'lastmsgfrom' => $lastpm['lastauthorusername'], 'lastmsg' => $lastpm['lastsummary']);
  59. }
  60. }
  61. elseif ($more == 4)
  62. {
  63. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm);
  64. }
  65. else
  66. {
  67. return 0;
  68. }
  69. }
  70. function onsendpm()
  71. {
  72. $this->init_input();
  73. $fromuid = $this->input('fromuid');
  74. $msgto = $this->input('msgto');
  75. $subject = $this->input('subject');
  76. $message = $this->input('message');
  77. $replypmid = $this->input('replypmid');
  78. $isusername = $this->input('isusername');
  79. $type = $this->input('type');
  80. if (!$fromuid)
  81. {
  82. return 0;
  83. }
  84. $user = $_ENV['user']->get_user_by_uid($fromuid);
  85. $user = daddslashes($user, 1);
  86. if (!$user)
  87. {
  88. return 0;
  89. }
  90. $this->user['uid'] = $user['uid'];
  91. $this->user['username'] = $user['username'];
  92. if ($replypmid)
  93. {
  94. $isusername = 0;
  95. $plid = $_ENV['pm']->getplidbypmid($replypmid);
  96. $msgto = $_ENV['pm']->getuidbyplid($plid);
  97. unset($msgto[$this->user['uid']]);
  98. }
  99. else
  100. {
  101. if (!empty($msgto))
  102. {
  103. $msgto = array_unique(explode(',', $msgto));
  104. }
  105. }
  106. if ($isusername)
  107. {
  108. $msgto = $_ENV['user']->name2id($msgto);
  109. }
  110. $countmsgto = count($msgto);
  111. if ($this->settings['pmsendregdays'])
  112. {
  113. if ($user['regdate'] > $this->time - $this->settings['pmsendregdays'] * 86400)
  114. {
  115. return PMSENDREGDAYS;
  116. }
  117. }
  118. if ($this->settings['chatpmmemberlimit'])
  119. {
  120. if ($type == 1 && ($countmsgto > ($this->settings['chatpmmemberlimit'] - 1)))
  121. {
  122. return CHATPMMEMBERLIMIT_ERROR;
  123. }
  124. }
  125. if ($this->settings['pmfloodctrl'])
  126. {
  127. if (!$_ENV['pm']->ispminterval($this->user['uid'], $this->settings['pmfloodctrl']))
  128. {
  129. return PMFLOODCTRL_ERROR;
  130. }
  131. }
  132. if ($this->settings['privatepmthreadlimit'])
  133. {
  134. if (!$_ENV['pm']->isprivatepmthreadlimit($this->user['uid'], $this->settings['privatepmthreadlimit']))
  135. {
  136. return PRIVATEPMTHREADLIMIT_ERROR;
  137. }
  138. }
  139. if ($this->settings['chatpmthreadlimit'])
  140. {
  141. if (!$_ENV['pm']->ischatpmthreadlimit($this->user['uid'], $this->settings['chatpmthreadlimit']))
  142. {
  143. return CHATPMTHREADLIMIT_ERROR;
  144. }
  145. }
  146. $lastpmid = 0;
  147. if ($replypmid)
  148. {
  149. $lastpmid = $_ENV['pm']->replypm($plid, $this->user['uid'], $this->user['username'], $message);
  150. }
  151. else
  152. {
  153. $lastpmid = $_ENV['pm']->sendpm($this->user['uid'], $this->user['username'], $msgto, $subject, $message, $type);
  154. }
  155. return $lastpmid;
  156. }
  157. function ondelete()
  158. {
  159. $this->init_input();
  160. $this->user['uid'] = intval($this->input('uid'));
  161. $pmids = $this->input('pmids');
  162. if (empty($pmids))
  163. {
  164. return 0;
  165. }
  166. if (is_array($pmids))
  167. {
  168. $this->apps = $this->cache('apps');
  169. if ($this->apps[$this->app['appid']]['type'] == 'UCHOME')
  170. {
  171. $id = $_ENV['pm']->deletepmbyplids($this->user['uid'], $this->input('pmids'));
  172. }
  173. else
  174. {
  175. $id = $_ENV['pm']->deletepmbypmids($this->user['uid'], $this->input('pmids'));
  176. }
  177. }
  178. else
  179. {
  180. $id = $_ENV['pm']->deletepmbypmid($this->user['uid'], $this->input('pmids'));
  181. }
  182. return $id;
  183. }
  184. function ondeletechat()
  185. {
  186. $this->init_input();
  187. $this->user['uid'] = intval($this->input('uid'));
  188. $plids = $this->input('plids');
  189. $type = intval($this->input('type'));
  190. if ($type == 1)
  191. {
  192. return $_ENV['pm']->deletepmbyplids($this->user['uid'], $plids);
  193. }
  194. else
  195. {
  196. return $_ENV['pm']->quitchatpm($this->user['uid'], $plids);
  197. }
  198. }
  199. function ondeleteuser()
  200. {
  201. $this->init_input();
  202. $this->user['uid'] = intval($this->input('uid'));
  203. $id = $_ENV['pm']->deletepmbyplids($this->user['uid'], $this->input('touids'), 1);
  204. return $id;
  205. }
  206. function onreadstatus()
  207. {
  208. $this->init_input();
  209. $this->user['uid'] = intval($this->input('uid'));
  210. $_ENV['pm']->setpmstatus($this->user['uid'], $this->input('uids'), $this->input('plids'), $this->input('status'));
  211. }
  212. function onignore()
  213. {
  214. $this->init_input();
  215. $this->user['uid'] = intval($this->input('uid'));
  216. return $_ENV['pm']->set_ignore($this->user['uid']);
  217. }
  218. function onls()
  219. {
  220. $this->init_input();
  221. $pagesize = $this->input('pagesize');
  222. $filter = $this->input('filter');
  223. $page = $this->input('page');
  224. $msglen = $this->input('msglen');
  225. $this->user['uid'] = intval($this->input('uid'));
  226. $filter = $filter ? (in_array($filter, array('newpm', 'privatepm')) ? $filter : '') : '';
  227. if ($filter == 'newpm')
  228. {
  229. $type = 0;
  230. $new = 1;
  231. }
  232. elseif ($filter == 'privatepm')
  233. {
  234. $type = 0;
  235. $new = 0;
  236. }
  237. else
  238. {
  239. return array();
  240. }
  241. $pmnum = $_ENV['pm']->getpmnum($this->user['uid'], $type, $new);
  242. $start = $this->page_get_start($page, $pagesize, $pmnum);
  243. if ($pagesize > 0)
  244. {
  245. $pms = $_ENV['pm']->getpmlist($this->user['uid'], $filter, $start, $pagesize);
  246. if (is_array($pms) && !empty($pms))
  247. {
  248. foreach ($pms as $key => $pm)
  249. {
  250. if ($msglen)
  251. {
  252. $pms[$key]['lastsummary'] = $_ENV['pm']->removecode($pms[$key]['lastsummary'], $msglen);
  253. }
  254. else
  255. {
  256. unset($pms[$key]['lastsummary']);
  257. }
  258. }
  259. }
  260. $result['data'] = $pms;
  261. }
  262. $result['count'] = $pmnum;
  263. return $result;
  264. }
  265. function onview()
  266. {
  267. $this->init_input();
  268. $this->user['uid'] = intval($this->input('uid'));
  269. $pmid = $this->input('pmid');
  270. $touid = $this->input('touid');
  271. $daterange = $this->input('daterange');
  272. $page = $this->input('page');
  273. $pagesize = $this->input('pagesize');
  274. $isplid = $this->input('isplid');
  275. $type = $this->input('type');
  276. $daterange = empty($daterange) ? 1 : $daterange;
  277. $today = $this->time - ($this->time + $this->settings['timeoffset']) % 86400;
  278. if ($daterange == 1)
  279. {
  280. $starttime = $today;
  281. }
  282. elseif ($daterange == 2)
  283. {
  284. $starttime = $today - 86400;
  285. }
  286. elseif ($daterange == 3)
  287. {
  288. $starttime = $today - 172800;
  289. }
  290. elseif ($daterange == 4)
  291. {
  292. $starttime = $today - 604800;
  293. }
  294. elseif ($daterange == 5)
  295. {
  296. $starttime = 0;
  297. }
  298. $endtime = $this->time;
  299. if (!$isplid)
  300. {
  301. $plid = $_ENV['pm']->getplidbytouid($this->user['uid'], $touid);
  302. }
  303. else
  304. {
  305. $plid = $touid;
  306. }
  307. if ($page)
  308. {
  309. $pmnum = $_ENV['pm']->getpmnumbyplid($this->user['uid'], $plid);
  310. $start = $this->page_get_start($page, $pagesize, $pmnum);
  311. $ppp = $pagesize;
  312. }
  313. else
  314. {
  315. $pmnum = 0;
  316. $start = 0;
  317. $ppp = 0;
  318. }
  319. if ($pmid)
  320. {
  321. $pms = $_ENV['pm']->getpmbypmid($this->user['uid'], $pmid);
  322. }
  323. else
  324. {
  325. $pms = $_ENV['pm']->getpmbyplid($this->user['uid'], $plid, $starttime, $endtime, $start, $ppp, $type);
  326. }
  327. require_once UC_ROOT . 'lib/uccode.class.php';
  328. $this->uccode = new uccode();
  329. if ($pms)
  330. {
  331. foreach ($pms as $key => $pm)
  332. {
  333. $pms[$key]['message'] = $this->uccode->complie($pms[$key]['message']);
  334. }
  335. }
  336. return $pms;
  337. }
  338. function onviewnum()
  339. {
  340. $this->init_input();
  341. $this->user['uid'] = intval($this->input('uid'));
  342. $touid = $this->input('touid');
  343. $isplid = $this->input('isplid');
  344. if (!$isplid)
  345. {
  346. $plid = $_ENV['pm']->getplidbytouid($this->user['uid'], $touid);
  347. }
  348. else
  349. {
  350. $plid = $touid;
  351. }
  352. $pmnum = $_ENV['pm']->getpmnumbyplid($this->user['uid'], $plid);
  353. return $pmnum;
  354. }
  355. function onviewnode()
  356. {
  357. $this->init_input();
  358. $this->user['uid'] = intval($this->input('uid'));
  359. $type = $this->input('type');
  360. $pmid = $this->input('pmid');
  361. $type = 0;
  362. $pms = $_ENV['pm']->getpmbypmid($this->user['uid'], $pmid);
  363. require_once UC_ROOT . 'lib/uccode.class.php';
  364. $this->uccode = new uccode();
  365. if ($pms)
  366. {
  367. foreach ($pms as $key => $pm)
  368. {
  369. $pms[$key]['message'] = $this->uccode->complie($pms[$key]['message']);
  370. }
  371. }
  372. $pms = $pms[0];
  373. return $pms;
  374. }
  375. function onchatpmmemberlist()
  376. {
  377. $this->init_input();
  378. $this->user['uid'] = intval($this->input('uid'));
  379. $plid = intval($this->input('plid'));
  380. return $_ENV['pm']->chatpmmemberlist($this->user['uid'], $plid);
  381. }
  382. function onkickchatpm()
  383. {
  384. $this->init_input();
  385. $this->user['uid'] = intval($this->input('uid'));
  386. $plid = intval($this->input('plid'));
  387. $touid = intval($this->input('touid'));
  388. return $_ENV['pm']->kickchatpm($plid, $this->user['uid'], $touid);
  389. }
  390. function onappendchatpm()
  391. {
  392. $this->init_input();
  393. $this->user['uid'] = intval($this->input('uid'));
  394. $plid = intval($this->input('plid'));
  395. $touid = intval($this->input('touid'));
  396. return $_ENV['pm']->appendchatpm($plid, $this->user['uid'], $touid);
  397. }
  398. function onblackls_get()
  399. {
  400. $this->init_input();
  401. $this->user['uid'] = intval($this->input('uid'));
  402. return $_ENV['pm']->get_blackls($this->user['uid']);
  403. }
  404. function onblackls_set()
  405. {
  406. $this->init_input();
  407. $this->user['uid'] = intval($this->input('uid'));
  408. $blackls = $this->input('blackls');
  409. return $_ENV['pm']->set_blackls($this->user['uid'], $blackls);
  410. }
  411. function onblackls_add()
  412. {
  413. $this->init_input();
  414. $this->user['uid'] = intval($this->input('uid'));
  415. $username = $this->input('username');
  416. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 1);
  417. }
  418. function onblackls_delete($arr)
  419. {
  420. $this->init_input();
  421. $this->user['uid'] = intval($this->input('uid'));
  422. $username = $this->input('username');
  423. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 2);
  424. }
  425. }