helper_pm.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: helper_pm.php 31440 2012-08-28 07:22:57Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class helper_pm {
  12. public static function sendpm($toid, $subject, $message, $fromid = '', $replypmid = 0, $isusername = 0, $type = 0) {
  13. global $_G;
  14. if($fromid === '') {
  15. $fromid = $_G['uid'];
  16. }
  17. $author = '';
  18. if($fromid) {
  19. if($fromid == $_G['uid']) {
  20. $sendpmmaxnum = $_G['group']['allowsendpmmaxnum'];
  21. $author = $_G['username'];
  22. } else {
  23. $user = getuserbyuid($fromid);
  24. $author = $user['username'];
  25. loadcache('usergroup_'.$user['groupid']);
  26. $sendpmmaxnum = $_G['cache']['usergroup_'.$user['groupid']]['allowsendpmmaxnum'];
  27. }
  28. $currentnum = C::t('common_member_action_log')->count_day_hours(getuseraction('pmid'), $fromid);
  29. if($sendpmmaxnum && $currentnum >= $sendpmmaxnum) {
  30. return -16;
  31. }
  32. }
  33. loaducenter();
  34. $return = uc_pm_send($fromid, $toid, addslashes($subject), addslashes($message), 1, $replypmid, $isusername, $type);
  35. if($return > 0 && $fromid) {
  36. if($_G['setting']['cloud_status']) {
  37. $msgService = Cloud::loadClass('Cloud_Service_Client_Message');
  38. if(is_numeric($toid)) {
  39. $msgService->add($toid, $fromid, $author, $_G['timestamp']);
  40. } else {
  41. $senduids = array();
  42. foreach(C::t('common_member')->fetch_all_by_username(explode(',', $toid)) as $touser) {
  43. $senduids[$touser['uid']] = $touser['uid'];
  44. }
  45. if($senduids) {
  46. $msgService->add($senduids, $fromid, $author, $_G['timestamp']);
  47. }
  48. }
  49. }
  50. foreach(explode(',', $fromid) as $v) {
  51. useractionlog($fromid, 'pmid');
  52. }
  53. }
  54. return $return;
  55. }
  56. }
  57. ?>