pm.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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 1160 2013-10-24 08:04:45Z jeffjzhang $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. define('PMINBALCKLIST_ERROR', -6);
  9. define('PMSENDSELF_ERROR', -8);
  10. define('PMSENDNONE_ERROR', -9);
  11. define('PMSENDCHATNUM_ERROR', -10);
  12. define('PMTHREADNONE_ERROR', -11);
  13. define('PMPRIVILEGENONE_ERROR', -12);
  14. define('PMCHATTYPE_ERROR', -13);
  15. define('PMUIDTYPE_ERROR', -14);
  16. define('PMDATA_ERROR', -15);
  17. class pmmodel
  18. {
  19. var $db;
  20. var $base;
  21. function __construct(&$base)
  22. {
  23. $this->pmmodel($base);
  24. }
  25. function pmmodel(&$base)
  26. {
  27. $this->base = $base;
  28. $this->db = $base->db;
  29. }
  30. function pmintval($pmid)
  31. {
  32. return @is_numeric($pmid) ? $pmid : 0;
  33. }
  34. function getpmbypmid($uid, $pmid)
  35. {
  36. if (!$pmid)
  37. {
  38. return array();
  39. }
  40. $arr = array();
  41. $pm = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_indexes i LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON t.plid=i.plid WHERE i.pmid='$pmid'");
  42. if ($this->isprivilege($pm['plid'], $uid))
  43. {
  44. $pms = $this->db->fetch_all("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM " . UC_DBTABLEPRE . $this->getposttablename($pm['plid']) . " p LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON t.plid=p.plid WHERE p.pmid='$pm[pmid]'");
  45. $arr = $this->getpostlist($pms);
  46. }
  47. return $arr;
  48. }
  49. function isprivilege($plid, $uid)
  50. {
  51. if (!$plid || !$uid)
  52. {
  53. return true;
  54. }
  55. $query = $this->db->query("SELECT * FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid' AND uid='$uid'");
  56. if ($this->db->fetch_array($query))
  57. {
  58. return true;
  59. }
  60. else
  61. {
  62. return false;
  63. }
  64. }
  65. function getpmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp, $type = 0)
  66. {
  67. if (!$type)
  68. {
  69. $pm = $this->getprivatepmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp);
  70. }
  71. else
  72. {
  73. $pm = $this->getchatpmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp);
  74. }
  75. return $this->getpostlist($pm);
  76. }
  77. function getpostlist($list)
  78. {
  79. if (empty($list))
  80. {
  81. return array();
  82. }
  83. $authoridarr = $authorarr = array();
  84. foreach ($list as $key => $value)
  85. {
  86. $authoridarr[$value['authorid']] = $value['authorid'];
  87. }
  88. if ($authoridarr)
  89. {
  90. $this->base->load('user');
  91. $authorarr = $_ENV['user']->id2name($authoridarr);
  92. }
  93. foreach ($list as $key => $value)
  94. {
  95. if ($value['pmtype'] == 1)
  96. {
  97. $users = explode('_', $value['min_max']);
  98. if ($value['authorid'] == $users[0])
  99. {
  100. $value['touid'] = $users[1];
  101. }
  102. else
  103. {
  104. $value['touid'] = $users[0];
  105. }
  106. }
  107. else
  108. {
  109. $value['touid'] = 0;
  110. }
  111. $value['author'] = $authorarr[$value['authorid']];
  112. $value['msgfromid'] = $value['authorid'];
  113. $value['msgfrom'] = $value['author'];
  114. $value['msgtoid'] = $value['touid'];
  115. unset($value['min_max']);
  116. unset($value['delstatus']);
  117. unset($value['lastmessage']);
  118. $list[$key] = $value;
  119. }
  120. return $list;
  121. }
  122. function setpmstatus($uid, $touids, $plids, $status = 0)
  123. {
  124. if (!$uid)
  125. {
  126. return false;
  127. }
  128. if (!$status)
  129. {
  130. $oldstatus = 1;
  131. $newstatus = 0;
  132. }
  133. else
  134. {
  135. $oldstatus = 0;
  136. $newstatus = 1;
  137. }
  138. if ($touids)
  139. {
  140. foreach ($touids as $key => $value)
  141. {
  142. if ($uid == $value || !$value)
  143. {
  144. return false;
  145. }
  146. $relastionship[] = $this->relationship($uid, $value);
  147. }
  148. $plid = $plidpostarr = array();
  149. $query = $this->db->query("SELECT plid FROM " . UC_DBTABLEPRE . "pm_lists WHERE min_max IN (" . $this->base->implode($relationship) . ")");
  150. while ($thread = $this->db->fetch_array($query))
  151. {
  152. $plidarr[] = $thread['plid'];
  153. }
  154. if ($plidarr)
  155. {
  156. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew='$newstatus' WHERE plid IN (" . $this->base->implode($plidarr) . ") AND uid='$uid' AND isnew='$oldstatus'");
  157. }
  158. }
  159. if ($plids)
  160. {
  161. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew='$newstatus' WHERE plid IN (" . $this->base->implode($plids) . ") AND uid='$uid' AND isnew='$oldstatus'");
  162. }
  163. return true;
  164. }
  165. function set_ignore($uid)
  166. {
  167. return $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "newpm WHERE uid='$uid'");
  168. }
  169. function isnewpm($uid)
  170. {
  171. return $this->db->result_first("SELECT uid FROM " . UC_DBTABLEPRE . "newpm WHERE uid='$uid'");
  172. }
  173. function lastpm($uid)
  174. {
  175. $lastpm = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_members m LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON m.plid=t.plid WHERE m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT 1");
  176. $lastmessage = unserialize($lastpm['lastmessage']);
  177. if ($lastmessage['lastauthorid'])
  178. {
  179. $lastpm['lastauthorid'] = $lastmessage['lastauthorid'];
  180. $lastpm['lastauthor'] = $lastmessage['lastauthor'];
  181. $lastpm['lastsummary'] = $lastmessage['lastsummary'];
  182. }
  183. else
  184. {
  185. $lastpm['lastauthorid'] = $lastmessage['firstauthorid'];
  186. $lastpm['lastauthor'] = $lastmessage['firstauthor'];
  187. $lastpm['lastsummary'] = $lastmessage['firstsummary'];
  188. }
  189. return $lastpm;
  190. }
  191. function getpmnum($uid, $type = 0, $isnew = 0)
  192. {
  193. $newsql = '';
  194. $newnum = 0;
  195. if ($isnew)
  196. {
  197. $newsql = 'AND m.isnew=1';
  198. }
  199. if (!$type)
  200. {
  201. $newnum = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_members m WHERE m.uid='$uid' $newsql");
  202. }
  203. else
  204. {
  205. $newnum = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_members m LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON t.plid=m.plid WHERE m.uid='$uid' $newsql AND t.pmtype='$type'");
  206. }
  207. return $newnum;
  208. }
  209. function getpmnumbyplid($uid, $plid)
  210. {
  211. return $this->db->result_first("SELECT pmnum FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid' AND uid='$uid'");
  212. }
  213. function sendpm($fromuid, $fromusername, $touids, $subject, $message, $type = 0)
  214. {
  215. if (!$fromuid || !$fromusername || !$touids || !$message)
  216. {
  217. return 0;
  218. }
  219. $touids = array_unique($touids);
  220. $relationship = $existplid = $pm_member_insertsql = array();
  221. $this->base->load('user');
  222. $tmptouidarr = $touids;
  223. $blackls = $this->get_blackls($fromuid, $touids);
  224. foreach ($tmptouidarr as $key => $value)
  225. {
  226. if ($fromuid == $value || !$value)
  227. {
  228. return PMSENDSELF_ERROR;
  229. }
  230. if (in_array('{ALL}', $blackls[$value]))
  231. {
  232. unset($touids[$key]);
  233. continue;
  234. }
  235. $blackls[$value] = $_ENV['user']->name2id($blackls[$value]);
  236. if (!(isset($blackls[$value]) && !in_array($fromuid, $blackls[$value])))
  237. {
  238. unset($touids[$key]);
  239. }
  240. else
  241. {
  242. $relationship[$value] = $this->relationship($fromuid, $value);
  243. }
  244. }
  245. if (empty($touids))
  246. {
  247. return PMSENDNONE_ERROR;
  248. }
  249. if ($type == 1 && count($touids) < 2)
  250. {
  251. return PMSENDCHATNUM_ERROR;
  252. }
  253. $_CACHE['badwords'] = $this->base->cache('badwords');
  254. if ($_CACHE['badwords']['findpattern'])
  255. {
  256. $subject = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $subject);
  257. $message = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $message);
  258. }
  259. if (!$subject)
  260. {
  261. $subject = $this->removecode(trim($message), 80);
  262. }
  263. else
  264. {
  265. $subject = dhtmlspecialchars($subject);
  266. }
  267. $lastsummary = $this->removecode(trim(stripslashes($message)), 150);
  268. if (!$type)
  269. {
  270. $query = $this->db->query("SELECT plid, min_max FROM " . UC_DBTABLEPRE . "pm_lists WHERE min_max IN (" . $this->base->implode($relationship) . ")");
  271. while ($thread = $this->db->fetch_array($query))
  272. {
  273. $existplid[$thread['min_max']] = $thread['plid'];
  274. }
  275. $lastmessage = array('lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
  276. $lastmessage = addslashes(serialize($lastmessage));
  277. foreach ($relationship as $key => $value)
  278. {
  279. if (!isset($existplid[$value]))
  280. {
  281. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_lists(authorid, pmtype, subject, members, min_max, dateline, lastmessage) VALUES('$fromuid', '1', '$subject', 2, '$value', '" . $this->base->time . "', '$lastmessage')");
  282. $plid = $this->db->insert_id();
  283. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_indexes(plid) VALUES('$plid')");
  284. $pmid = $this->db->insert_id();
  285. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . $this->getposttablename($plid) . "(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '" . $this->base->time . "', 0)");
  286. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$key', '1', '1', '0', '" . $this->base->time . "')");
  287. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$fromuid', '0', '1', '" . $this->base->time . "', '" . $this->base->time . "')");
  288. }
  289. else
  290. {
  291. $plid = $existplid[$value];
  292. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_indexes(plid) VALUES('$plid')");
  293. $pmid = $this->db->insert_id();
  294. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . $this->getposttablename($plid) . "(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '" . $this->base->time . "', 0)");
  295. $result = $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$key', '1', '1', '0', '" . $this->base->time . "')", 'SILENT');
  296. if (!$result)
  297. {
  298. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='" . $this->base->time . "' WHERE plid='$plid' AND uid='$key'");
  299. }
  300. $result = $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$fromuid', '0', '1', '" . $this->base->time . "', '" . $this->base->time . "')", 'SILENT');
  301. if (!$result)
  302. {
  303. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=0, pmnum=pmnum+1, lastupdate='" . $this->base->time . "', lastdateline='" . $this->base->time . "' WHERE plid='$plid' AND uid='$fromuid'");
  304. }
  305. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_lists SET lastmessage='$lastmessage' WHERE plid='$plid'");
  306. }
  307. }
  308. }
  309. else
  310. {
  311. $lastmessage = array('firstauthorid' => $fromuid, 'firstauthor' => $fromusername, 'firstsummary' => $lastsummary);
  312. $lastmessage = addslashes(serialize($lastmessage));
  313. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_lists(authorid, pmtype, subject, members, min_max, dateline, lastmessage) VALUES('$fromuid', '2', '$subject', '" . (count($touids) + 1) . "', '', '" . $this->base->time . "', '$lastmessage')");
  314. $plid = $this->db->insert_id();
  315. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_indexes(plid) VALUES('$plid')");
  316. $pmid = $this->db->insert_id();
  317. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . $this->getposttablename($plid) . "(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '" . $this->base->time . "', 0)");
  318. $pm_member_insertsql[] = "('$plid', '$fromuid', '0', '1', '" . $this->base->time . "', '" . $this->base->time . "')";
  319. foreach ($touids as $key => $value)
  320. {
  321. $pm_member_insertsql[] = "('$plid', '$value', '1', '1', '0', '" . $this->base->time . "')";
  322. }
  323. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES " . implode(',', $pm_member_insertsql));
  324. }
  325. $newpm = array();
  326. foreach ($touids as $key => $value)
  327. {
  328. $newpm[] = "('$value')";
  329. }
  330. $this->db->query("REPLACE INTO " . UC_DBTABLEPRE . "newpm(uid) VALUES " . implode(',', $newpm));
  331. return $pmid;
  332. }
  333. function replypm($plid, $fromuid, $fromusername, $message)
  334. {
  335. if (!$plid || !$fromuid || !$fromusername || !$message)
  336. {
  337. return 0;
  338. }
  339. $threadpm = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'");
  340. if (empty($threadpm))
  341. {
  342. return PMTHREADNONE_ERROR;
  343. }
  344. if ($threadpm['pmtype'] == 1)
  345. {
  346. $users = explode('_', $threadpm['min_max']);
  347. if ($users[0] == $fromuid)
  348. {
  349. $touid = $users[1];
  350. }
  351. elseif ($users[1] == $fromuid)
  352. {
  353. $touid = $users[0];
  354. }
  355. else
  356. {
  357. return PMPRIVILEGENONE_ERROR;
  358. }
  359. $blackls = $this->get_blackls($fromuid, $touid);
  360. if (in_array('{ALL}', $blackls[$touid]))
  361. {
  362. return PMINBALCKLIST_ERROR;
  363. }
  364. $this->base->load('user');
  365. $blackls[$touid] = $_ENV['user']->name2id($blackls[$touid]);
  366. if (!(isset($blackls[$touid]) && !in_array($fromuid, $blackls[$touid])))
  367. {
  368. return PMINBALCKLIST_ERROR;
  369. }
  370. }
  371. $memberuid = array();
  372. $query = $this->db->query("SELECT * FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid'");
  373. while ($member = $this->db->fetch_array($query))
  374. {
  375. $memberuid[$member['uid']] = "('$member[uid]')";
  376. }
  377. if (!isset($memberuid[$fromuid]))
  378. {
  379. return PMPRIVILEGENONE_ERROR;
  380. }
  381. $_CACHE['badwords'] = $this->base->cache('badwords');
  382. if ($_CACHE['badwords']['findpattern'])
  383. {
  384. $message = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $message);
  385. }
  386. $lastsummary = $this->removecode(trim(stripslashes($message)), 150);
  387. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_indexes(plid) VALUES('$plid')");
  388. $pmid = $this->db->insert_id();
  389. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . $this->getposttablename($plid) . "(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '" . $this->base->time . "', 0)");
  390. if ($threadpm['pmtype'] == 1)
  391. {
  392. $lastmessage = array('lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
  393. $lastmessage = addslashes(serialize($lastmessage));
  394. $result = $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$touid', '1', '1', '0', '" . $this->base->time . "')", 'SILENT');
  395. if (!$result)
  396. {
  397. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='" . $this->base->time . "' WHERE plid='$plid' AND uid='$touid'");
  398. }
  399. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=0, pmnum=pmnum+1, lastupdate='" . $this->base->time . "', lastdateline='" . $this->base->time . "' WHERE plid='$plid' AND uid='$fromuid'");
  400. }
  401. else
  402. {
  403. $lastmessage = unserialize($threadpm['lastmessage']);
  404. $lastmessage = array('firstauthorid' => $lastmessage['firstauthorid'], 'firstauthor' => $lastmessage['firstauthor'], 'firstsummary' => $lastmessage['firstsummary'], 'lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
  405. $lastmessage = addslashes(serialize($lastmessage));
  406. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='" . $this->base->time . "' WHERE plid='$plid'");
  407. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=0, lastupdate='" . $this->base->time . "' WHERE plid='$plid' AND uid='$fromuid'");
  408. }
  409. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_lists SET lastmessage='$lastmessage' WHERE plid='$plid'");
  410. $this->db->query("REPLACE INTO " . UC_DBTABLEPRE . "newpm(uid) VALUES " . implode(',', $memberuid) . "");
  411. return $pmid;
  412. }
  413. function appendchatpm($plid, $uid, $touid)
  414. {
  415. if (!$plid || !$uid || !$touid)
  416. {
  417. return 0;
  418. }
  419. $threadpm = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'");
  420. if (empty($threadpm))
  421. {
  422. return PMTHREADNONE_ERROR;
  423. }
  424. if ($threadpm['pmtype'] != 2)
  425. {
  426. return PMCHATTYPE_ERROR;
  427. }
  428. if ($threadpm['authorid'] != $uid)
  429. {
  430. return PMPRIVILEGENONE_ERROR;
  431. }
  432. $blackls = $this->get_blackls($uid, $touid);
  433. if (in_array('{ALL}', $blackls[$touid]))
  434. {
  435. return PMINBALCKLIST_ERROR;
  436. }
  437. $this->base->load('user');
  438. $blackls[$touid] = $_ENV['user']->name2id($blackls[$touid]);
  439. if (!(isset($blackls[$touid]) && !in_array($uid, $blackls[$touid])))
  440. {
  441. return PMINBALCKLIST_ERROR;
  442. }
  443. $pmnum = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . $this->getposttablename($plid) . " WHERE plid='$plid'");
  444. $this->db->query("INSERT INTO " . UC_DBTABLEPRE . "pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$touid', '1', '$pmnum', '0', '0')", 'SILENT');
  445. $num = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid'");
  446. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_lists SET members='$num' WHERE plid='$plid'");
  447. return 1;
  448. }
  449. function kickchatpm($plid, $uid, $touid)
  450. {
  451. if (!$uid || !$touid || !$plid || $uid == $touid)
  452. {
  453. return 0;
  454. }
  455. $threadpm = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'");
  456. if ($threadpm['pmtype'] != 2)
  457. {
  458. return PMCHATTYPE_ERROR;
  459. }
  460. if ($threadpm['authorid'] != $uid)
  461. {
  462. return PMPRIVILEGENONE_ERROR;
  463. }
  464. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid' AND uid='$touid'");
  465. $num = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid'");
  466. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_lists SET members='$num' WHERE plid='$plid'");
  467. return 1;
  468. }
  469. function quitchatpm($uid, $plids)
  470. {
  471. if (!$uid || !$plids)
  472. {
  473. return 0;
  474. }
  475. $list = array();
  476. $query = $this->db->query("SELECT * FROM " . UC_DBTABLEPRE . "pm_members m LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON m.plid=t.plid WHERE m.plid IN (" . $this->base->implode($plids) . ") AND m.uid='$uid'");
  477. while ($threadpm = $this->db->fetch_array($query))
  478. {
  479. if ($threadpm['pmtype'] != 2)
  480. {
  481. return PMCHATTYPE_ERROR;
  482. }
  483. if ($threadpm['authorid'] == $uid)
  484. {
  485. return PMPRIVILEGENONE_ERROR;
  486. }
  487. $list[] = $threadpm['plid'];
  488. }
  489. if ($list)
  490. {
  491. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid IN (" . $this->base->implode($list) . ") AND uid='$uid'");
  492. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_lists SET members=members-1 WHERE plid IN (" . $this->base->implode($list) . ")");
  493. }
  494. return 1;
  495. }
  496. function deletepmbypmid($uid, $pmid)
  497. {
  498. if (!$uid || !$pmid)
  499. {
  500. return 0;
  501. }
  502. $index = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_indexes i LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON i.plid=t.plid WHERE i.pmid='$pmid'");
  503. if ($index['pmtype'] != 1)
  504. {
  505. return PMUIDTYPE_ERROR;
  506. }
  507. $users = explode('_', $index['min_max']);
  508. if (!in_array($uid, $users))
  509. {
  510. return PMPRIVILEGENONE_ERROR;
  511. }
  512. if ($index['authorid'] != $uid)
  513. {
  514. $this->db->query("UPDATE " . UC_DBTABLEPRE . $this->getposttablename($index['plid']) . " SET delstatus=2 WHERE pmid='$pmid' AND delstatus=0");
  515. $updatenum = $this->db->affected_rows();
  516. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . $this->getposttablename($index['plid']) . " WHERE pmid='$pmid' AND delstatus=1");
  517. $deletenum = $this->db->affected_rows();
  518. }
  519. else
  520. {
  521. $this->db->query("UPDATE " . UC_DBTABLEPRE . $this->getposttablename($index['plid']) . " SET delstatus=1 WHERE pmid='$pmid' AND delstatus=0");
  522. $updatenum = $this->db->affected_rows();
  523. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . $this->getposttablename($index['plid']) . " WHERE pmid='$pmid' AND delstatus=2");
  524. $deletenum = $this->db->affected_rows();
  525. }
  526. if (!$this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . $this->getposttablename($index['plid']) . " WHERE plid='$index[plid]'"))
  527. {
  528. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$index[plid]'");
  529. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$index[plid]'");
  530. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_indexes WHERE plid='$index[plid]'");
  531. }
  532. else
  533. {
  534. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET pmnum=pmnum-" . ($updatenum + $deletenum) . " WHERE plid='" . $index['plid'] . "' AND uid='$uid'");
  535. }
  536. return 1;
  537. }
  538. function deletepmbypmids($uid, $pmids)
  539. {
  540. if ($pmids)
  541. {
  542. foreach ($pmids as $key => $pmid)
  543. {
  544. $this->deletepmbypmid($uid, $pmid);
  545. }
  546. }
  547. return 1;
  548. }
  549. /*
  550. function deletepmbypmids($uid, $pmids) {
  551. if(!$uid || !$pmids) {
  552. return 0;
  553. }
  554. $pmplid = $delstatus1pm = $delstatus2pm = $pmplidpost = array();
  555. $existplid = array();
  556. $query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."pm_indexes i LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON i.plid=t.plid WHERE i.pmid IN (".$this->base->implode($pmids).") AND t.pmtype=1");
  557. while($index = $this->db->fetch_array($query)) {
  558. $users = explode('_', $index['min_max']);
  559. if(!in_array($uid, $users)) {
  560. return PMPRIVILEGENONE_ERROR;
  561. }
  562. if($index['authorid'] == $uid) {
  563. $delstatus1pm[$this->getposttablename($index['plid'])][] = $index['pmid'];
  564. } else {
  565. $delstatus2pm[$this->getposttablename($index['plid'])][] = $index['pmid'];
  566. }
  567. $pmplidpost[$this->getposttablename($index['plid'])][] = $index['plid'];
  568. $pmplid[$index['plid']] = $index['plid'];
  569. }
  570. if(empty($pmplidpost)) {
  571. return 0;
  572. }
  573. if($delstatus1pm) {
  574. foreach($delstatus1pm as $key => $value) {
  575. $this->db->query("UPDATE ".UC_DBTABLEPRE."$key SET delstatus=1 WHERE pmid IN (".$this->base->implode($value).") AND delstatus=0");
  576. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."$key WHERE pmid IN (".$this->base->implode($value).") AND delstatus=2");
  577. }
  578. }
  579. if($delstatus2pm) {
  580. foreach($delstatus2pm as $key => $value) {
  581. $this->db->query("UPDATE ".UC_DBTABLEPRE."$key SET delstatus=2 WHERE pmid IN (".$this->base->implode($value).") AND delstatus=0");
  582. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."$key WHERE pmid IN (".$this->base->implode($value).") AND delstatus=1");
  583. }
  584. }
  585. foreach($pmplidpost as $key => $value) {
  586. $query = $this->db->query("SELECT DISTINCT plid FROM ".UC_DBTABLEPRE."$key WHERE plid IN (".$this->base->implode($value).")");
  587. while($pmpostarr = $this->db->fetch_array($query)) {
  588. $existplid[] = $pmpostarr['plid'];
  589. }
  590. }
  591. $pmplid = array_diff($pmplid, $existplid);
  592. if($pmplid) {
  593. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid IN (".$this->base->implode($pmplid).")");
  594. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid IN (".$this->base->implode($pmplid).")");
  595. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid IN (".$this->base->implode($pmplid).")");
  596. }
  597. return 1;
  598. }
  599. */
  600. function deletepmbyplid($uid, $plid, $isuser = 0)
  601. {
  602. if (!$uid || !$plid)
  603. {
  604. return 0;
  605. }
  606. if ($isuser)
  607. {
  608. $relationship = $this->relationship($uid, $plid);
  609. $sql = "SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE min_max='$relationship'";
  610. }
  611. else
  612. {
  613. $sql = "SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'";
  614. }
  615. $query = $this->db->query($sql);
  616. if ($list = $this->db->fetch_array($query))
  617. {
  618. if ($list['pmtype'] == 1)
  619. {
  620. $user = explode('_', $list['min_max']);
  621. if (!in_array($uid, $user))
  622. {
  623. return PMPRIVILEGENONE_ERROR;
  624. }
  625. }
  626. else
  627. {
  628. if ($uid != $list['authorid'])
  629. {
  630. return PMPRIVILEGENONE_ERROR;
  631. }
  632. }
  633. }
  634. else
  635. {
  636. return PMTHREADNONE_ERROR;
  637. }
  638. if ($list['pmtype'] == 1)
  639. {
  640. if ($uid == $list['authorid'])
  641. {
  642. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " WHERE plid='$list[plid]' AND delstatus=2");
  643. $this->db->query("UPDATE " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " SET delstatus=1 WHERE plid='$list[plid]' AND delstatus=0");
  644. }
  645. else
  646. {
  647. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " WHERE plid='$list[plid]' AND delstatus=1");
  648. $this->db->query("UPDATE " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " SET delstatus=2 WHERE plid='$list[plid]' AND delstatus=0");
  649. }
  650. $count = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " WHERE plid='$list[plid]'");
  651. if (!$count)
  652. {
  653. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$list[plid]'");
  654. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$list[plid]'");
  655. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_indexes WHERE plid='$list[plid]'");
  656. }
  657. else
  658. {
  659. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$list[plid]' AND uid='$uid'");
  660. }
  661. }
  662. else
  663. {
  664. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . $this->getposttablename($list['plid']) . " WHERE plid='$list[plid]'");
  665. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$list[plid]'");
  666. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$list[plid]'");
  667. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "pm_indexes WHERE plid='$list[plid]'");
  668. }
  669. return 1;
  670. }
  671. function deletepmbyplids($uid, $plids, $isuser = 0)
  672. {
  673. if ($plids)
  674. {
  675. foreach ($plids as $key => $plid)
  676. {
  677. $this->deletepmbyplid($uid, $plid, $isuser);
  678. }
  679. }
  680. return 1;
  681. }
  682. /*
  683. function deletepmbyplid($uid, $plids, $isuser = 0) {
  684. if(!$uid || !$plids) {
  685. return 0;
  686. }
  687. $privatepm = $chatpm = array();
  688. $privatepmauthorpost = $privatepmpost = $privatepmpostall = array();
  689. $existplid = array();
  690. if($isuser) {
  691. $relationship = array();
  692. foreach($plids as $key => $value) {
  693. if($uid == $value || !$value) {
  694. return PMDATA_ERROR;
  695. }
  696. $relationship[] = $this->relationship($uid, $value);
  697. }
  698. $sql = "SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE min_max IN (".$this->base->implode($relationship).")";
  699. } else {
  700. $sql = "SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid IN (".$this->base->implode($plids).")";
  701. }
  702. $query = $this->db->query($sql);
  703. while($threadpm = $this->db->fetch_array($query)) {
  704. if($threadpm['pmtype'] == 1) {
  705. $users = explode('_', $threadpm['min_max']);
  706. if($users[0] == $uid) {
  707. $touid = $users[1];
  708. } elseif($users[1] == $uid) {
  709. $touid = $users[0];
  710. } else {
  711. continue;
  712. }
  713. if($threadpm['authorid'] == $uid) {
  714. $privatepmauthorpost[$this->getposttablename($threadpm['plid'])][] = $threadpm['plid'];
  715. } else {
  716. $privatepmpost[$this->getposttablename($threadpm['plid'])][] = $threadpm['plid'];
  717. }
  718. $privatepmpostall[$this->getposttablename($threadpm['plid'])][] = $threadpm['plid'];
  719. $privatepm[] = $threadpm['plid'];
  720. } else {
  721. if($uid != $threadpm['authorid']) {
  722. continue;
  723. }
  724. $chatpm[] = $threadpm['plid'];
  725. $chatpmpost[$this->getposttablename($threadpm['plid'])][] = $threadpm['plid'];
  726. }
  727. }
  728. if($privatepmauthorpost) {
  729. foreach($privatepmauthorpost as $key => $value) {
  730. $this->db->query("UPDATE ".UC_DBTABLEPRE."$key SET delstatus=1 WHERE plid IN (".$this->base->implode($value).") AND delstatus=0");
  731. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."$key WHERE plid IN (".$this->base->implode($value).") AND delstatus=2");
  732. }
  733. }
  734. if($privatepmpost) {
  735. foreach($privatepmpost as $key => $value) {
  736. $this->db->query("UPDATE ".UC_DBTABLEPRE."$key SET delstatus=2 WHERE plid IN (".$this->base->implode($value).") AND delstatus=0");
  737. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."$key WHERE plid IN (".$this->base->implode($value).") AND delstatus=1");
  738. }
  739. }
  740. if($privatepmpostall) {
  741. foreach($privatepmpostall as $key => $value) {
  742. $query = $this->db->query("SELECT DISTINCT plid FROM ".UC_DBTABLEPRE."$key WHERE plid IN (".$this->base->implode($value).")");
  743. while($postpm = $this->db->fetch_array($query)) {
  744. $existplid[] = $postpm['plid'];
  745. }
  746. }
  747. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid IN (".$this->base->implode($privatepm).") AND uid='$uid'");
  748. $privatepm = array_diff($privatepm, $existplid);
  749. if(!empty($privatepm)) {
  750. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid IN (".$this->base->implode($privatepm).")");
  751. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid IN (".$this->base->implode($privatepm).")");
  752. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid IN (".$this->base->implode($privatepm).")");
  753. }
  754. }
  755. if($chatpmpost) {
  756. foreach($chatpmpost as $key => $value) {
  757. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."$key WHERE plid IN (".$this->base->implode($value).")");
  758. }
  759. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid IN (".$this->base->implode($chatpm).")");
  760. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid IN (".$this->base->implode($chatpm).")");
  761. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid IN (".$this->base->implode($chatpm).")");
  762. }
  763. return 1;
  764. }
  765. */
  766. function getprivatepmbyplid($uid, $plid, $starttime = 0, $endtime = 0, $start = 0, $ppp = 0)
  767. {
  768. if (!$uid || !$plid)
  769. {
  770. return 0;
  771. }
  772. if (!$this->isprivilege($plid, $uid))
  773. {
  774. return 0;
  775. }
  776. $thread = $this->db->fetch_first("SELECT * FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'");
  777. if ($thread['pmtype'] != 1)
  778. {
  779. return 0;
  780. }
  781. $pms = $addsql = array();
  782. $addsql[] = "p.plid='$plid'";
  783. if ($thread['authorid'] == $uid)
  784. {
  785. $addsql[] = 'p.delstatus IN (0,2)';
  786. }
  787. else
  788. {
  789. $addsql[] = 'p.delstatus IN (0,1)';
  790. }
  791. if ($starttime)
  792. {
  793. $addsql[] = "p.dateline>'$starttime'";
  794. }
  795. if ($endtime)
  796. {
  797. $addsql[] = "p.dateline<'$endtime'";
  798. }
  799. if ($addsql)
  800. {
  801. $addsql = implode(' AND ', $addsql);
  802. }
  803. else
  804. {
  805. $addsql = '';
  806. }
  807. if ($ppp)
  808. {
  809. $limitsql = 'LIMIT ' . intval($start) . ', ' . intval($ppp);
  810. }
  811. else
  812. {
  813. $limitsql = '';
  814. }
  815. $pms = $this->db->fetch_all("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM " . UC_DBTABLEPRE . $this->getposttablename($plid) . " p LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON p.plid=t.plid WHERE $addsql ORDER BY p.dateline DESC $limitsql");
  816. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=0 WHERE plid='$plid' AND uid='$uid' AND isnew=1");
  817. return array_reverse($pms);
  818. }
  819. function getchatpmbyplid($uid, $plid, $starttime = 0, $endtime = 0, $start = 0, $ppp = 0)
  820. {
  821. if (!$uid || !$plid)
  822. {
  823. return 0;
  824. }
  825. if (!$this->isprivilege($plid, $uid))
  826. {
  827. return 0;
  828. }
  829. $pms = $addsql = array();
  830. $addsql[] = "p.plid='$plid'";
  831. if ($starttime)
  832. {
  833. $addsql[] = "p.dateline>'$starttime'";
  834. }
  835. if ($endtime)
  836. {
  837. $addsql[] = "p.dateline<'$endtime'";
  838. }
  839. if ($addsql)
  840. {
  841. $addsql = implode(' AND ', $addsql);
  842. }
  843. else
  844. {
  845. $addsql = '';
  846. }
  847. if ($ppp)
  848. {
  849. $limitsql = 'LIMIT ' . intval($start) . ', ' . intval($ppp);
  850. }
  851. else
  852. {
  853. $limitsql = '';
  854. }
  855. $query = $this->db->query("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM " . UC_DBTABLEPRE . $this->getposttablename($plid) . " p LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON p.plid=t.plid WHERE $addsql ORDER BY p.dateline DESC $limitsql");
  856. while ($pm = $this->db->fetch_array($query))
  857. {
  858. if ($pm['pmtype'] != 2)
  859. {
  860. return 0;
  861. }
  862. $pms[] = $pm;
  863. }
  864. $this->db->query("UPDATE " . UC_DBTABLEPRE . "pm_members SET isnew=0 WHERE plid='$plid' AND uid='$uid' AND isnew=1");
  865. return array_reverse($pms);
  866. }
  867. function getpmlist($uid, $filter, $start, $ppp = 10)
  868. {
  869. if (!$uid)
  870. {
  871. return 0;
  872. }
  873. $members = $touidarr = $tousernamearr = array();
  874. if ($filter == 'newpm')
  875. {
  876. $addsql = 'm.isnew=1 AND ';
  877. }
  878. else
  879. {
  880. $addsql = '';
  881. }
  882. $query = $this->db->query("SELECT * FROM " . UC_DBTABLEPRE . "pm_members m LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON t.plid=m.plid WHERE $addsql m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT $start, $ppp");
  883. while ($member = $this->db->fetch_array($query))
  884. {
  885. if ($member['pmtype'] == 1)
  886. {
  887. $users = explode('_', $member['min_max']);
  888. $member['touid'] = $users[0] == $uid ? $users[1] : $users[0];
  889. }
  890. else
  891. {
  892. $member['touid'] = 0;
  893. }
  894. $touidarr[$member['touid']] = $member['touid'];
  895. $members[] = $member;
  896. }
  897. $this->db->query("DELETE FROM " . UC_DBTABLEPRE . "newpm WHERE uid='$uid'");
  898. $array = array();
  899. if ($members)
  900. {
  901. $today = $this->base->time - $this->base->time % 86400;
  902. $this->base->load('user');
  903. $tousernamearr = $_ENV['user']->id2name($touidarr);
  904. foreach ($members as $key => $data)
  905. {
  906. $daterange = 5;
  907. $data['founddateline'] = $data['dateline'];
  908. $data['dateline'] = $data['lastdateline'];
  909. $data['pmid'] = $data['plid'];
  910. $lastmessage = unserialize($data['lastmessage']);
  911. if ($lastmessage['firstauthorid'])
  912. {
  913. $data['firstauthorid'] = $lastmessage['firstauthorid'];
  914. $data['firstauthor'] = $lastmessage['firstauthor'];
  915. $data['firstsummary'] = $lastmessage['firstsummary'];
  916. }
  917. if ($lastmessage['lastauthorid'])
  918. {
  919. $data['lastauthorid'] = $lastmessage['lastauthorid'];
  920. $data['lastauthor'] = $lastmessage['lastauthor'];
  921. $data['lastsummary'] = $lastmessage['lastsummary'];
  922. }
  923. $data['msgfromid'] = $lastmessage['lastauthorid'];
  924. $data['msgfrom'] = $lastmessage['lastauthor'];
  925. $data['message'] = $lastmessage['lastsummary'];
  926. $data['new'] = $data['isnew'];
  927. $data['msgtoid'] = $data['touid'];
  928. if ($data['lastdateline'] >= $today)
  929. {
  930. $daterange = 1;
  931. }
  932. elseif ($data['lastdateline'] >= $today - 86400)
  933. {
  934. $daterange = 2;
  935. }
  936. elseif ($data['lastdateline'] >= $today - 172800)
  937. {
  938. $daterange = 3;
  939. }
  940. elseif ($data['lastdateline'] >= $today - 604800)
  941. {
  942. $daterange = 4;
  943. }
  944. $data['daterange'] = $daterange;
  945. $data['tousername'] = $tousernamearr[$data['touid']];
  946. unset($data['min_max']);
  947. $array[] = $data;
  948. }
  949. }
  950. return $array;
  951. }
  952. function getplidbypmid($pmid)
  953. {
  954. if (!$pmid)
  955. {
  956. return false;
  957. }
  958. return $this->db->result_first("SELECT plid FROM " . UC_DBTABLEPRE . "pm_indexes WHERE pmid='$pmid'");
  959. }
  960. function getplidbytouid($uid, $touid)
  961. {
  962. if (!$uid || !$touid)
  963. {
  964. return 0;
  965. }
  966. return $this->db->result_first("SELECT plid FROM " . UC_DBTABLEPRE . "pm_lists WHERE min_max='" . $this->relationship($uid, $touid) . "'");
  967. }
  968. function getuidbyplid($plid)
  969. {
  970. if (!$plid)
  971. {
  972. return array();
  973. }
  974. $uidarr = array();
  975. $query = $this->db->query("SELECT uid FROM " . UC_DBTABLEPRE . "pm_members WHERE plid='$plid'");
  976. while ($uid = $this->db->fetch_array($query))
  977. {
  978. $uidarr[$uid['uid']] = $uid['uid'];
  979. }
  980. return $uidarr;
  981. }
  982. function chatpmmemberlist($uid, $plid)
  983. {
  984. if (!$uid || !$plid)
  985. {
  986. return 0;
  987. }
  988. $uidarr = $this->getuidbyplid($plid);
  989. if (empty($uidarr))
  990. {
  991. return 0;
  992. }
  993. if (!isset($uidarr[$uid]))
  994. {
  995. return 0;
  996. }
  997. $authorid = $this->db->result_first("SELECT authorid FROM " . UC_DBTABLEPRE . "pm_lists WHERE plid='$plid'");
  998. return array('author' => $authorid, 'member' => $uidarr);
  999. }
  1000. function relationship($fromuid, $touid)
  1001. {
  1002. if ($fromuid < $touid)
  1003. {
  1004. return $fromuid . '_' . $touid;
  1005. }
  1006. elseif ($fromuid > $touid)
  1007. {
  1008. return $touid . '_' . $fromuid;
  1009. }
  1010. else
  1011. {
  1012. return '';
  1013. }
  1014. }
  1015. function getposttablename($plid)
  1016. {
  1017. $id = substr((string) $plid, -1, 1);
  1018. return 'pm_messages_' . intval($id);
  1019. }
  1020. function get_blackls($uid, $uids = array())
  1021. {
  1022. if (!$uids)
  1023. {
  1024. $blackls = $this->db->result_first("SELECT blacklist FROM " . UC_DBTABLEPRE . "memberfields WHERE uid='$uid'");
  1025. }
  1026. else
  1027. {
  1028. $uids = $this->base->implode($uids);
  1029. $blackls = array();
  1030. $query = $this->db->query("SELECT uid, blacklist FROM " . UC_DBTABLEPRE . "memberfields WHERE uid IN ($uids)");
  1031. while ($data = $this->db->fetch_array($query))
  1032. {
  1033. $blackls[$data['uid']] = explode(',', $data['blacklist']);
  1034. }
  1035. }
  1036. return $blackls;
  1037. }
  1038. function set_blackls($uid, $blackls)
  1039. {
  1040. $this->db->query("UPDATE " . UC_DBTABLEPRE . "memberfields SET blacklist='$blackls' WHERE uid='$uid'");
  1041. return $this->db->affected_rows();
  1042. }
  1043. function update_blackls($uid, $username, $action = 1)
  1044. {
  1045. $username = !is_array($username) ? array($username) : $username;
  1046. if ($action == 1)
  1047. {
  1048. if (!in_array('{ALL}', $username))
  1049. {
  1050. $usernames = $this->base->implode($username);
  1051. $query = $this->db->query("SELECT username FROM " . UC_DBTABLEPRE . "members WHERE username IN ($usernames)");
  1052. $usernames = array();
  1053. while ($data = $this->db->fetch_array($query))
  1054. {
  1055. $usernames[addslashes($data['username'])] = addslashes($data['username']);
  1056. }
  1057. if (!$usernames)
  1058. {
  1059. return 0;
  1060. }
  1061. $blackls = addslashes($this->db->result_first("SELECT blacklist FROM " . UC_DBTABLEPRE . "memberfields WHERE uid='$uid'"));
  1062. if ($blackls)
  1063. {
  1064. $list = explode(',', $blackls);
  1065. foreach ($list as $k => $v)
  1066. {
  1067. if (in_array($v, $usernames))
  1068. {
  1069. unset($usernames[$v]);
  1070. }
  1071. }
  1072. }
  1073. if (!$usernames)
  1074. {
  1075. return 1;
  1076. }
  1077. $listnew = implode(',', $usernames);
  1078. $blackls .= $blackls !== '' ? ',' . $listnew : $listnew;
  1079. }
  1080. else
  1081. {
  1082. $blackls = addslashes($this->db->result_first("SELECT blacklist FROM " . UC_DBTABLEPRE . "memberfields WHERE uid='$uid'"));
  1083. $blackls .= ',{ALL}';
  1084. }
  1085. }
  1086. else
  1087. {
  1088. $blackls = addslashes($this->db->result_first("SELECT blacklist FROM " . UC_DBTABLEPRE . "memberfields WHERE uid='$uid'"));
  1089. $list = $blackls = explode(',', $blackls);
  1090. foreach ($list as $k => $v)
  1091. {
  1092. if (in_array($v, $username))
  1093. {
  1094. unset($blackls[$k]);
  1095. }
  1096. }
  1097. $blackls = implode(',', $blackls);
  1098. }
  1099. $this->db->query("UPDATE " . UC_DBTABLEPRE . "memberfields SET blacklist='$blackls' WHERE uid='$uid'");
  1100. return 1;
  1101. }
  1102. function removecode($str, $length)
  1103. {
  1104. static $uccode = null;
  1105. if ($uccode === null)
  1106. {
  1107. require_once UC_ROOT . 'lib/uccode.class.php';
  1108. $uccode = new uccode();
  1109. }
  1110. $str = $uccode->complie($str);
  1111. return trim($this->base->cutstr(strip_tags($str), $length));
  1112. }
  1113. function ispminterval($uid, $interval = 0)
  1114. {
  1115. if (!$uid)
  1116. {
  1117. return 0;
  1118. }
  1119. $interval = intval($interval);
  1120. if (!$interval)
  1121. {
  1122. return 1;
  1123. }
  1124. $lastupdate = $this->db->result_first("SELECT lastupdate FROM " . UC_DBTABLEPRE . "pm_members WHERE uid='$uid' ORDER BY lastupdate DESC LIMIT 1");
  1125. if (($this->base->time - $lastupdate) > $interval)
  1126. {
  1127. return 1;
  1128. }
  1129. else
  1130. {
  1131. return 0;
  1132. }
  1133. }
  1134. function isprivatepmthreadlimit($uid, $maxnum = 0)
  1135. {
  1136. if (!$uid)
  1137. {
  1138. return 0;
  1139. }
  1140. $maxnum = intval($maxnum);
  1141. if (!$maxnum)
  1142. {
  1143. return 1;
  1144. }
  1145. $num = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_members m LEFT JOIN " . UC_DBTABLEPRE . "pm_lists t ON m.plid=t.plid WHERE uid='$uid' AND lastupdate>'" . ($this->base->time - 86400) . "' AND t.pmtype=1");
  1146. if ($maxnum - $num < 0)
  1147. {
  1148. return 0;
  1149. }
  1150. else
  1151. {
  1152. return 1;
  1153. }
  1154. }
  1155. function ischatpmthreadlimit($uid, $maxnum = 0)
  1156. {
  1157. if (!$uid)
  1158. {
  1159. return 0;
  1160. }
  1161. $maxnum = intval($maxnum);
  1162. if (!$maxnum)
  1163. {
  1164. return 1;
  1165. }
  1166. $num = $this->db->result_first("SELECT COUNT(*) FROM " . UC_DBTABLEPRE . "pm_lists WHERE authorid='$uid' AND dateline>'" . ($this->base->time - 86400) . "'");
  1167. if ($maxnum - $num < 0)
  1168. {
  1169. return 0;
  1170. }
  1171. else
  1172. {
  1173. return 1;
  1174. }
  1175. }
  1176. }