PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/uc_client/control/pm.php

https://github.com/gcao/bbs
PHP | 255 lines | 225 code | 24 blank | 6 comment | 51 complexity | 5177a612e495321723e088a843916bd7 MD5 | raw file
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: pm.php 836 2008-12-05 02:25:48Z monkey $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. define('PMLIMIT1DAY_ERROR', -1);
  9. define('PMFLOODCTRL_ERROR', -2);
  10. define('PMMSGTONOTFRIEND', -3);
  11. define('PMSENDREGDAYS', -4);
  12. class pmcontrol extends base {
  13. function __construct() {
  14. $this->pmcontrol();
  15. }
  16. function pmcontrol() {
  17. parent::__construct();
  18. $this->load('user');
  19. $this->load('pm');
  20. }
  21. function oncheck_newpm() {
  22. $this->init_input();
  23. $this->user['uid'] = intval($this->input('uid'));
  24. $more = $this->input('more');
  25. $result = $_ENV['pm']->check_newpm($this->user['uid'], $more);
  26. if($more == 3) {
  27. require_once UC_ROOT.'lib/uccode.class.php';
  28. $this->uccode = new uccode();
  29. $result['lastmsg'] = $this->uccode->complie($result['lastmsg']);
  30. }
  31. return $result;
  32. }
  33. function onsendpm() {
  34. $this->init_input();
  35. $fromuid = $this->input('fromuid');
  36. $msgto = $this->input('msgto');
  37. $subject = $this->input('subject');
  38. $message = $this->input('message');
  39. $replypmid = $this->input('replypmid');
  40. $isusername = $this->input('isusername');
  41. if($fromuid) {
  42. $user = $_ENV['user']->get_user_by_uid($fromuid);
  43. $user = daddslashes($user, 1);
  44. if(!$user) {
  45. return 0;
  46. }
  47. $this->user['uid'] = $user['uid'];
  48. $this->user['username'] = $user['username'];
  49. } else {
  50. $this->user['uid'] = 0;
  51. $this->user['username'] = '';
  52. }
  53. if($replypmid) {
  54. $isusername = 1;
  55. $pms = $_ENV['pm']->get_pm_by_pmid($this->user['uid'], $replypmid);
  56. if($pms[0]['msgfromid'] == $this->user['uid']) {
  57. $user = $_ENV['user']->get_user_by_uid($pms[0]['msgtoid']);
  58. $msgto = $user['username'];
  59. } else {
  60. $msgto = $pms[0]['msgfrom'];
  61. }
  62. }
  63. $msgto = array_unique(explode(',', $msgto));
  64. $isusername && $msgto = $_ENV['user']->name2id($msgto);
  65. $blackls = $_ENV['pm']->get_blackls($this->user['uid'], $msgto);
  66. if($fromuid) {
  67. if($this->settings['pmsendregdays']) {
  68. if($user['regdate'] > $this->time - $this->settings['pmsendregdays'] * 86400) {
  69. return PMSENDREGDAYS;
  70. }
  71. }
  72. $this->load('friend');
  73. if(count($msgto) > 1 && !($is_friend = $_ENV['friend']->is_friend($fromuid, $msgto, 3))) {
  74. return PMMSGTONOTFRIEND;
  75. }
  76. $pmlimit1day = $this->settings['pmlimit1day'] && $_ENV['pm']->count_pm_by_fromuid($this->user['uid'], 86400) > $this->settings['pmlimit1day'];
  77. if($pmlimit1day || ($this->settings['pmfloodctrl'] && $_ENV['pm']->count_pm_by_fromuid($this->user['uid'], $this->settings['pmfloodctrl']))) {
  78. if(!$_ENV['friend']->is_friend($fromuid, $msgto, 3)) {
  79. if(!$_ENV['pm']->is_reply_pm($fromuid, $msgto)) {
  80. if($pmlimit1day) {
  81. return PMLIMIT1DAY_ERROR;
  82. } else {
  83. return PMFLOODCTRL_ERROR;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. $lastpmid = 0;
  90. foreach($msgto as $uid) {
  91. if(!$fromuid || !in_array('{ALL}', $blackls[$uid])) {
  92. $blackls[$uid] = $_ENV['user']->name2id($blackls[$uid]);
  93. if(!$fromuid || isset($blackls[$uid]) && !in_array($this->user['uid'], $blackls[$uid])) {
  94. $lastpmid = $_ENV['pm']->sendpm($subject, $message, $this->user, $uid, $replypmid);
  95. }
  96. }
  97. }
  98. return $lastpmid;
  99. }
  100. function ondelete() {
  101. $this->init_input();
  102. $this->user['uid'] = intval($this->input('uid'));
  103. $id = $_ENV['pm']->deletepm($this->user['uid'], $this->input('pmids'));
  104. return $id;
  105. }
  106. function ondeleteuser() {
  107. $this->init_input();
  108. $this->user['uid'] = intval($this->input('uid'));
  109. $id = $_ENV['pm']->deleteuidpm($this->user['uid'], $this->input('touids'));
  110. return $id;
  111. }
  112. function onreadstatus() {
  113. $this->init_input();
  114. $this->user['uid'] = intval($this->input('uid'));
  115. $_ENV['pm']->set_pm_status($this->user['uid'], $this->input('uids'), $this->input('pmids'), $this->input('status'));
  116. }
  117. function onignore() {
  118. $this->init_input();
  119. $this->user['uid'] = intval($this->input('uid'));
  120. return $_ENV['pm']->set_ignore($this->user['uid']);
  121. }
  122. function onls() {
  123. $this->init_input();
  124. $pagesize = $this->input('pagesize');
  125. $folder = $this->input('folder');
  126. $filter = $this->input('filter');
  127. $page = $this->input('page');
  128. $folder = in_array($folder, array('newbox', 'inbox', 'outbox', 'searchbox')) ? $folder : 'inbox';
  129. if($folder != 'searchbox') {
  130. $filter = $filter ? (in_array($filter, array('newpm', 'privatepm', 'systempm', 'announcepm')) ? $filter : '') : '';
  131. }
  132. $msglen = $this->input('msglen');
  133. $this->user['uid'] = intval($this->input('uid'));
  134. if($folder != 'searchbox') {
  135. $pmnum = $_ENV['pm']->get_num($this->user['uid'], $folder, $filter);
  136. $start = $this->page_get_start($page, $pagesize, $pmnum);
  137. } else {
  138. $pmnum = $pagesize;
  139. $start = ($page - 1) * $pagesize;
  140. }
  141. if($pagesize > 0) {
  142. $pms = $_ENV['pm']->get_pm_list($this->user['uid'], $pmnum, $folder, $filter, $start, $pagesize);
  143. if(is_array($pms) && !empty($pms)) {
  144. foreach($pms as $key => $pm) {
  145. if($msglen) {
  146. $pms[$key]['message'] = htmlspecialchars($_ENV['pm']->removecode($pms[$key]['message'], $msglen));
  147. } else {
  148. unset($pms[$key]['message']);
  149. }
  150. unset($pms[$key]['folder']);
  151. }
  152. }
  153. $result['data'] = $pms;
  154. }
  155. $result['count'] = $pmnum;
  156. return $result;
  157. }
  158. function onviewnode() {
  159. $this->init_input();
  160. $this->user['uid'] = intval($this->input('uid'));
  161. $pmid = $_ENV['pm']->pmintval($this->input('pmid'));
  162. $type = $this->input('type');
  163. $pm = $_ENV['pm']->get_pmnode_by_pmid($this->user['uid'], $pmid, $type);
  164. if($pm) {
  165. require_once UC_ROOT.'lib/uccode.class.php';
  166. $this->uccode = new uccode();
  167. $pm['message'] = $this->uccode->complie($pm['message']);
  168. return $pm;
  169. }
  170. }
  171. function onview() {
  172. $this->init_input();
  173. $this->user['uid'] = intval($this->input('uid'));
  174. $touid = $this->input('touid');
  175. $pmid = $_ENV['pm']->pmintval($this->input('pmid'));
  176. $daterange = $this->input('daterange');
  177. if(empty($pmid)) {
  178. $daterange = empty($daterange) ? 1 : $daterange;
  179. $today = $this->time - ($this->time + $this->settings['timeoffset']) % 86400;
  180. if($daterange == 1) {
  181. $starttime = $today;
  182. } elseif($daterange == 2) {
  183. $starttime = $today - 86400;
  184. } elseif($daterange == 3) {
  185. $starttime = $today - 172800;
  186. } elseif($daterange == 4) {
  187. $starttime = $today - 604800;
  188. } elseif($daterange == 5) {
  189. $starttime = 0;
  190. }
  191. $endtime = $this->time;
  192. $pms = $_ENV['pm']->get_pm_by_touid($this->user['uid'], $touid, $starttime, $endtime);
  193. } else {
  194. $pms = $_ENV['pm']->get_pm_by_pmid($this->user['uid'], $pmid);
  195. }
  196. require_once UC_ROOT.'lib/uccode.class.php';
  197. $this->uccode = new uccode();
  198. $status = FALSE;
  199. foreach($pms as $key => $pm) {
  200. $pms[$key]['message'] = $this->uccode->complie($pms[$key]['message']);
  201. !$status && $status = $pm['msgtoid'] && $pm['new'];
  202. }
  203. $status && $_ENV['pm']->set_pm_status($this->user['uid'], $touid, $pmid);
  204. return $pms;
  205. }
  206. function onblackls_get() {
  207. $this->init_input();
  208. $this->user['uid'] = intval($this->input('uid'));
  209. return $_ENV['pm']->get_blackls($this->user['uid']);
  210. }
  211. function onblackls_set() {
  212. $this->init_input();
  213. $this->user['uid'] = intval($this->input('uid'));
  214. $blackls = $this->input('blackls');
  215. return $_ENV['pm']->set_blackls($this->user['uid'], $blackls);
  216. }
  217. function onblackls_add() {
  218. $this->init_input();
  219. $this->user['uid'] = intval($this->input('uid'));
  220. $username = $this->input('username');
  221. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 1);
  222. }
  223. function onblackls_delete($arr) {
  224. $this->init_input();
  225. $this->user['uid'] = intval($this->input('uid'));
  226. $username = $this->input('username');
  227. return $_ENV['pm']->update_blackls($this->user['uid'], $username, 2);
  228. }
  229. }
  230. ?>