PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/uc_server/control/pm.php

https://github.com/AlexChien/EY_BBS
PHP | 255 lines | 225 code | 24 blank | 6 comment | 51 complexity | 737034bcb857a079822cfe06d9c9c736 MD5 | raw file
Possible License(s): Apache-2.0
  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 857 2008-12-09 09:48:05Z 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. $this->load('user');
  69. if($user['regdate'] > $this->time - $this->settings['pmsendregdays'] * 86400) {
  70. return PMSENDREGDAYS;
  71. }
  72. }
  73. $this->load('friend');
  74. if(count($msgto) > 1 && !($is_friend = $_ENV['friend']->is_friend($fromuid, $msgto, 3))) {
  75. return PMMSGTONOTFRIEND;
  76. }
  77. $pmlimit1day = $this->settings['pmlimit1day'] && $_ENV['pm']->count_pm_by_fromuid($this->user['uid'], 86400) > $this->settings['pmlimit1day'];
  78. if($pmlimit1day || ($this->settings['pmfloodctrl'] && $_ENV['pm']->count_pm_by_fromuid($this->user['uid'], $this->settings['pmfloodctrl']))) {
  79. if(!$_ENV['friend']->is_friend($fromuid, $msgto, 3)) {
  80. if(!$_ENV['pm']->is_reply_pm($fromuid, $msgto)) {
  81. if($pmlimit1day) {
  82. return PMLIMIT1DAY_ERROR;
  83. } else {
  84. return PMFLOODCTRL_ERROR;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. $lastpmid = 0;
  91. foreach($msgto as $uid) {
  92. if(!$fromuid || !in_array('{ALL}', $blackls[$uid])) {
  93. $blackls[$uid] = $_ENV['user']->name2id($blackls[$uid]);
  94. if(!$fromuid || isset($blackls[$uid]) && !in_array($this->user['uid'], $blackls[$uid])) {
  95. $lastpmid = $_ENV['pm']->sendpm($subject, $message, $this->user, $uid, 0, 0, $replypmid);
  96. }
  97. }
  98. }
  99. return $lastpmid;
  100. }
  101. function ondelete() {
  102. $this->init_input();
  103. $this->user['uid'] = intval($this->input('uid'));
  104. $id = $_ENV['pm']->deletepm($this->user['uid'], $this->input('pmids'));
  105. return $id;
  106. }
  107. function ondeleteuser() {
  108. $this->init_input();
  109. $this->user['uid'] = intval($this->input('uid'));
  110. $id = $_ENV['pm']->deleteuidpm($this->user['uid'], $this->input('touids'));
  111. return $id;
  112. }
  113. function onreadstatus() {
  114. $this->init_input();
  115. $this->user['uid'] = intval($this->input('uid'));
  116. $_ENV['pm']->set_pm_status($this->user['uid'], $this->input('uids'), $this->input('pmids'), $this->input('status'));
  117. }
  118. function onignore() {
  119. $this->init_input();
  120. $this->user['uid'] = intval($this->input('uid'));
  121. return $_ENV['pm']->set_ignore($this->user['uid']);
  122. }
  123. function onls() {
  124. $this->init_input();
  125. $pagesize = $this->input('pagesize');
  126. $folder = $this->input('folder');
  127. $filter = $this->input('filter');
  128. $page = $this->input('page');
  129. $folder = in_array($folder, array('newbox', 'inbox', 'searchbox')) ? $folder : 'inbox';
  130. if($folder != 'searchbox') {
  131. $filter = $filter ? (in_array($filter, array('newpm', 'privatepm', 'systempm', 'announcepm')) ? $filter : '') : '';
  132. }
  133. $msglen = $this->input('msglen');
  134. $this->user['uid'] = intval($this->input('uid'));
  135. if($folder != 'searchbox') {
  136. $pmnum = $_ENV['pm']->get_num($this->user['uid'], $folder, $filter);
  137. } else {
  138. $pmnum = $pagesize;
  139. }
  140. if($pagesize > 0) {
  141. $pms = $_ENV['pm']->get_pm_list($this->user['uid'], $pmnum, $folder, $filter, $page, $pagesize);
  142. if(is_array($pms) && !empty($pms)) {
  143. foreach($pms as $key => $pm) {
  144. if($msglen) {
  145. $pms[$key]['message'] = htmlspecialchars($_ENV['pm']->removecode($pms[$key]['message'], $msglen));
  146. } else {
  147. unset($pms[$key]['message']);
  148. }
  149. $pms[$key]['dateline'] = $pms[$key]['dbdateline'];
  150. unset($pms[$key]['dbdateline'], $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. ?>