pm.php 37 KB

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