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