pm.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. function __construct() {
  16. $this->pmcontrol();
  17. }
  18. function pmcontrol() {
  19. parent::__construct();
  20. $this->load('user');
  21. $this->load('pm');
  22. }
  23. function oncheck_newpm() {
  24. $this->init_input();
  25. $uid = intval($this->input('uid'));
  26. $more = intval($this->input('more'));
  27. if(!$_ENV['pm']->isnewpm($uid) && !$more) {
  28. return 0;
  29. }
  30. $newprvpm = $_ENV['pm']->getpmnum($uid, 1, 1);
  31. $newchatpm = $_ENV['pm']->getpmnum($uid, 2, 1);
  32. $newpm = $newprvpm + $newchatpm;
  33. if($more == 0) {
  34. return $newpm;
  35. } elseif($more == 1) {
  36. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm);
  37. } elseif($more == 2 || $more == 3) {
  38. if($more == 2) {
  39. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm);
  40. } else {
  41. $lastpm = $_ENV['pm']->lastpm($uid);
  42. require_once UC_ROOT.'lib/uccode.class.php';
  43. $this->uccode = new uccode();
  44. $lastpm['lastsummary'] = $this->uccode->complie($lastpm['lastsummary']);
  45. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm, 'lastdate' => $lastpm['lastdateline'], 'lastmsgfromid' => $lastpm['lastauthorid'], 'lastmsgfrom' => $lastpm['lastauthorusername'], 'lastmsg' => $lastpm['lastsummary']);
  46. }
  47. } elseif($more == 4) {
  48. return array('newpm' => $newpm, 'newprivatepm' => $newprvpm, 'newchatpm' => $newchatpm);
  49. } else {
  50. return 0;
  51. }
  52. }
  53. function onsendpm() {
  54. $this->init_input();
  55. $fromuid = $this->input('fromuid');
  56. $msgto = $this->input('msgto');
  57. $subject = $this->input('subject');
  58. $message = $this->input('message');
  59. $replypmid = $this->input('replypmid');
  60. $isusername = $this->input('isusername');
  61. $type = $this->input('type');
  62. if(!$fromuid) {
  63. return 0;
  64. }
  65. $user = $_ENV['user']->get_user_by_uid($fromuid);
  66. $user = daddslashes($user, 1);
  67. if(!$user) {
  68. return 0;
  69. }
  70. $this->user['uid'] = $user['uid'];
  71. $this->user['username'] = $user['username'];
  72. if($replypmid) {
  73. $isusername = 0;
  74. $plid = $_ENV['pm']->getplidbypmid($replypmid);
  75. $msgto = $_ENV['pm']->getuidbyplid($plid);
  76. unset($msgto[$this->user['uid']]);
  77. } else {
  78. if(!empty($msgto)) {
  79. $msgto = array_unique(explode(',', $msgto));
  80. }
  81. }
  82. if($isusername) {
  83. $msgto = $_ENV['user']->name2id($msgto);
  84. }
  85. $countmsgto = count($msgto);
  86. if($this->settings['pmsendregdays']) {
  87. if($user['regdate'] > $this->time - $this->settings['pmsendregdays'] * 86400) {
  88. return PMSENDREGDAYS;
  89. }
  90. }
  91. if($this->settings['chatpmmemberlimit']) {
  92. if($type == 1 && ($countmsgto > ($this->settings['chatpmmemberlimit'] - 1))) {
  93. return CHATPMMEMBERLIMIT_ERROR;
  94. }
  95. }
  96. if($this->settings['pmfloodctrl']) {
  97. if(!$_ENV['pm']->ispminterval($this->user['uid'], $this->settings['pmfloodctrl'])) {
  98. return PMFLOODCTRL_ERROR;
  99. }
  100. }
  101. if($this->settings['privatepmthreadlimit']) {
  102. if(!$_ENV['pm']->isprivatepmthreadlimit($this->user['uid'], $this->settings['privatepmthreadlimit'])) {
  103. return PRIVATEPMTHREADLIMIT_ERROR;
  104. }
  105. }
  106. if($this->settings['chatpmthreadlimit']) {
  107. if(!$_ENV['pm']->ischatpmthreadlimit($this->user['uid'], $this->settings['chatpmthreadlimit'])) {
  108. return CHATPMTHREADLIMIT_ERROR;
  109. }
  110. }
  111. $lastpmid = 0;
  112. if($replypmid) {
  113. $lastpmid = $_ENV['pm']->replypm($plid, $this->user['uid'], $this->user['username'], $message);
  114. } else {
  115. $lastpmid = $_ENV['pm']->sendpm($this->user['uid'], $this->user['username'], $msgto, $subject, $message, $type);
  116. }
  117. return $lastpmid;
  118. }
  119. function ondelete() {
  120. $this->init_input();
  121. $this->user['uid'] = intval($this->input('uid'));
  122. $pmids = $this->input('pmids');
  123. if(empty($pmids)) {
  124. return 0;
  125. }
  126. if(is_array($pmids)) {
  127. $this->apps = $this->cache('apps');
  128. if($this->apps[$this->app['appid']]['type'] == 'UCHOME') {
  129. $id = $_ENV['pm']->deletepmbyplids($this->user['uid'], $this->input('pmids'));
  130. } else {
  131. $id = $_ENV['pm']->deletepmbypmids($this->user['uid'], $this->input('pmids'));
  132. }
  133. } else {
  134. $id = $_ENV['pm']->deletepmbypmid($this->user['uid'], $this->input('pmids'));
  135. }
  136. return $id;
  137. }
  138. function ondeletechat() {
  139. $this->init_input();
  140. $this->user['uid'] = intval($this->input('uid'));
  141. $plids = $this->input('plids');
  142. $type = intval($this->input('type'));
  143. if($type == 1) {
  144. return $_ENV['pm']->deletepmbyplids($this->user['uid'], $plids);
  145. } else {
  146. return $_ENV['pm']->quitchatpm($this->user['uid'], $plids);
  147. }
  148. }
  149. function ondeleteuser() {
  150. $this->init_input();
  151. $this->user['uid'] = intval($this->input('uid'));
  152. $id = $_ENV['pm']->deletepmbyplids($this->user['uid'], $this->input('touids'), 1);
  153. return $id;
  154. }
  155. function onreadstatus() {
  156. $this->init_input();
  157. $this->user['uid'] = intval($this->input('uid'));
  158. $_ENV['pm']->setpmstatus($this->user['uid'], $this->input('uids'), $this->input('plids'), $this->input('status'));
  159. }
  160. function onignore() {
  161. $this->init_input();
  162. $this->user['uid'] = intval($this->input('uid'));
  163. return $_ENV['pm']->set_ignore($this->user['uid']);
  164. }
  165. function onls() {
  166. $this->init_input();
  167. $pagesize = $this->input('pagesize');
  168. $filter = $this->input('filter');
  169. $page = $this->input('page');
  170. $msglen = $this->input('msglen');
  171. $this->user['uid'] = intval($this->input('uid'));
  172. $filter = $filter ? (in_array($filter, array('newpm', 'privatepm')) ? $filter : '') : '';
  173. if($filter == 'newpm') {
  174. $type = 0;
  175. $new = 1;
  176. /*
  177. } elseif($filter == 'privatepm') {
  178. $type = 1;
  179. $new = 0;
  180. } elseif($filter == 'chatpm') {
  181. $type = 2;
  182. $new = 0;
  183. */
  184. } elseif($filter == 'privatepm') {
  185. $type = 0;
  186. $new = 0;
  187. } else {
  188. return array();
  189. }
  190. $pmnum = $_ENV['pm']->getpmnum($this->user['uid'], $type, $new);
  191. $start = $this->page_get_start($page, $pagesize, $pmnum);
  192. if($pagesize > 0) {
  193. $pms = $_ENV['pm']->getpmlist($this->user['uid'], $filter, $start, $pagesize);
  194. if(is_array($pms) && !empty($pms)) {
  195. foreach($pms as $key => $pm) {
  196. if($msglen) {
  197. $pms[$key]['lastsummary'] = $_ENV['pm']->removecode($pms[$key]['lastsummary'], $msglen);
  198. } else {
  199. unset($pms[$key]['lastsummary']);
  200. }
  201. }
  202. }
  203. $result['data'] = $pms;
  204. }
  205. $result['count'] = $pmnum;
  206. return $result;
  207. }
  208. function onview() {
  209. $this->init_input();
  210. $this->user['uid'] = intval($this->input('uid'));
  211. $pmid = $this->input('pmid');
  212. $touid = $this->input('touid');
  213. $daterange = $this->input('daterange');
  214. $page = $this->input('page');
  215. $pagesize = $this->input('pagesize');
  216. $isplid = $this->input('isplid');
  217. $type = $this->input('type');
  218. $daterange = empty($daterange) ? 1 : $daterange;
  219. $today = $this->time - ($this->time + $this->settings['timeoffset']) % 86400;
  220. if($daterange == 1) {
  221. $starttime = $today;
  222. } elseif($daterange == 2) {
  223. $starttime = $today - 86400;
  224. } elseif($daterange == 3) {
  225. $starttime = $today - 172800;
  226. } elseif($daterange == 4) {
  227. $starttime = $today - 604800;
  228. } elseif($daterange == 5) {
  229. $starttime = 0;
  230. }
  231. $endtime = $this->time;
  232. if(!$isplid) {
  233. $plid = $_ENV['pm']->getplidbytouid($this->user['uid'], $touid);
  234. } else {
  235. $plid = $touid;
  236. }
  237. if($page) {
  238. $pmnum = $_ENV['pm']->getpmnumbyplid($this->user['uid'], $plid);
  239. $start = $this->page_get_start($page, $pagesize, $pmnum);
  240. $ppp = $pagesize;
  241. } else {
  242. $pmnum = 0;
  243. $start = 0;
  244. $ppp = 0;
  245. }
  246. if($pmid) {
  247. $pms = $_ENV['pm']->getpmbypmid($this->user['uid'], $pmid);
  248. } else {
  249. $pms = $_ENV['pm']->getpmbyplid($this->user['uid'], $plid, $starttime, $endtime, $start, $ppp, $type);
  250. }
  251. require_once UC_ROOT.'lib/uccode.class.php';
  252. $this->uccode = new uccode();
  253. if($pms) {
  254. foreach($pms as $key => $pm) {
  255. $pms[$key]['message'] = $this->uccode->complie($pms[$key]['message']);
  256. }
  257. }
  258. return $pms;
  259. }
  260. function onviewnum() {
  261. $this->init_input();
  262. $this->user['uid'] = intval($this->input('uid'));
  263. $touid = $this->input('touid');
  264. $isplid = $this->input('isplid');
  265. if(!$isplid) {
  266. $plid = $_ENV['pm']->getplidbytouid($this->user['uid'], $touid);
  267. } else {
  268. $plid = $touid;
  269. }
  270. $pmnum = $_ENV['pm']->getpmnumbyplid($this->user['uid'], $plid);
  271. return $pmnum;
  272. }
  273. function onviewnode() {
  274. $this->init_input();
  275. $this->user['uid'] = intval($this->input('uid'));
  276. $type = $this->input('type');
  277. $pmid = $this->input('pmid');
  278. $type = 0;
  279. $pms = $_ENV['pm']->getpmbypmid($this->user['uid'], $pmid);
  280. require_once UC_ROOT.'lib/uccode.class.php';
  281. $this->uccode = new uccode();
  282. if($pms) {
  283. foreach($pms as $key => $pm) {
  284. $pms[$key]['message'] = $this->uccode->complie($pms[$key]['message']);
  285. }
  286. }
  287. $pms = $pms[0];
  288. return $pms;
  289. }
  290. function onchatpmmemberlist() {
  291. $this->init_input();
  292. $this->user['uid'] = intval($this->input('uid'));
  293. $plid = intval($this->input('plid'));
  294. return $_ENV['pm']->chatpmmemberlist($this->user['uid'], $plid);
  295. }
  296. function onkickchatpm() {
  297. $this->init_input();
  298. $this->user['uid'] = intval($this->input('uid'));
  299. $plid = intval($this->input('plid'));
  300. $touid = intval($this->input('touid'));
  301. return $_ENV['pm']->kickchatpm($plid, $this->user['uid'], $touid);
  302. }
  303. function onappendchatpm() {
  304. $this->init_input();
  305. $this->user['uid'] = intval($this->input('uid'));
  306. $plid = intval($this->input('plid'));
  307. $touid = intval($this->input('touid'));
  308. return $_ENV['pm']->appendchatpm($plid, $this->user['uid'], $touid);
  309. }
  310. function onblackls_get() {
  311. $this->init_input();
  312. $this->user['uid'] = intval($this->input('uid'));
  313. return $_ENV['pm']->get_blackls($this->user['uid']);
  314. }
  315. function onblackls_set() {
  316. $this->init_input();
  317. $this->user['uid'] = intval($this->input('uid'));
  318. $blackls = $this->input('blackls');
  319. return $_ENV['pm']->set_blackls($this->user['uid'], $blackls);
  320. }
  321. function onblackls_add() {
  322. $this->init_input();
  323. $this->user['uid'] = intval($this->input('uid'));
  324. $username = $this->input('username');
  325. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 1);
  326. }
  327. function onblackls_delete($arr) {
  328. $this->init_input();
  329. $this->user['uid'] = intval($this->input('uid'));
  330. $username = $this->input('username');
  331. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 2);
  332. }
  333. }
  334. ?>