extend_thread_allowat.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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: extend_thread_allowat.php 34144 2013-10-21 05:56:02Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class extend_thread_allowat extends extend_thread_base {
  12. public $atlist;
  13. public $allowat;
  14. public function before_newthread($parameters) {
  15. if($this->group['allowat']) {
  16. $this->atlist = $atlist_tmp = array();
  17. preg_match_all("/@([^\r\n]*?)\s/i", $parameters['message'].' ', $atlist_tmp);
  18. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $this->group['allowat']);
  19. if(!empty($atlist_tmp)) {
  20. if(!$this->setting['at_anyone']) {
  21. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($this->member['uid'], $atlist_tmp) as $row) {
  22. $this->atlist[$row['followuid']] = $row['fusername'];
  23. }
  24. if(count($this->atlist) < $this->group['allowat']) {
  25. $query = C::t('home_friend')->fetch_all_by_uid_username($this->member['uid'], $atlist_tmp);
  26. foreach($query as $row) {
  27. $this->atlist[$row['fuid']] = $row['fusername'];
  28. }
  29. }
  30. } else {
  31. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  32. $this->atlist[$row['uid']] = $row['username'];
  33. }
  34. }
  35. }
  36. if($this->atlist) {
  37. foreach($this->atlist as $atuid => $atusername) {
  38. $atsearch[] = "/@".str_replace('/', '\/', preg_quote($atusername))." /i";
  39. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  40. }
  41. $this->param['message'] = preg_replace($atsearch, $atreplace, $parameters['message'].' ', 1);
  42. $this->param['message'] = substr($this->param['message'], 0, strlen($this->param['message']) - 1);
  43. }
  44. }
  45. }
  46. public function after_newthread() {
  47. if($this->group['allowat'] && $this->atlist) {
  48. foreach($this->atlist as $atuid => $atusername) {
  49. notification_add($atuid, 'at', 'at_message', array('from_id' => $this->tid, 'from_idtype' => 'at', 'buyerid' => $this->member['uid'], 'buyer' => $this->member['username'], 'tid' => $this->tid, 'subject' => $this->param['subject'], 'pid' => $this->pid, 'message' => messagecutstr($this->param['message'], 150)));
  50. }
  51. set_atlist_cookie(array_keys($this->atlist));
  52. }
  53. }
  54. public function before_newreply($parameters) {
  55. if($this->group['allowat']) {
  56. $atlist_tmp = $ateduids = array();
  57. preg_match_all("/@([^\r\n]*?)\s/i", $parameters['message'].' ', $atlist_tmp);
  58. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $this->group['allowat']);
  59. $atnum = $maxselect = 0;
  60. foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($this->member['uid'], $this->thread['tid'], 'at') as $row) {
  61. $atnum ++;
  62. $ateduids[$row[uid]] = $row['uid'];
  63. }
  64. $maxselect = $this->group['allowat'] - $atnum;
  65. if($maxselect > 0 && !empty($atlist_tmp)) {
  66. $at_anyone = $this->setting['at_anyone'];
  67. if(empty($at_anyone)) {
  68. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($this->member['uid'], $atlist_tmp) as $row) {
  69. if(!in_array($row['followuid'], $ateduids)) {
  70. $this->atlist[$row[followuid]] = $row['fusername'];
  71. }
  72. if(count($this->atlist) == $maxselect) {
  73. break;
  74. }
  75. }
  76. if(count($this->atlist) < $maxselect) {
  77. $query = C::t('home_friend')->fetch_all_by_uid_username($this->member['uid'], $atlist_tmp);
  78. foreach($query as $row) {
  79. if(!in_array($row['followuid'], $ateduids)) {
  80. $this->atlist[$row[fuid]] = $row['fusername'];
  81. }
  82. }
  83. }
  84. } else {
  85. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  86. if(!in_array($row['uid'], $ateduids)) {
  87. $this->atlist[$row[uid]] = $row['username'];
  88. }
  89. if(count($this->atlist) == $maxselect) {
  90. break;
  91. }
  92. }
  93. }
  94. }
  95. if($this->atlist) {
  96. foreach($this->atlist as $atuid => $atusername) {
  97. $atsearch[] = "/@$atusername /i";
  98. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  99. }
  100. $this->param['message'] = preg_replace($atsearch, $atreplace, $parameters['message'].' ', 1);
  101. $this->param['message'] = substr($this->param['message'], 0, strlen($this->param['message']) - 1);
  102. }
  103. }
  104. }
  105. public function after_newreply() {
  106. if($this->group['allowat'] && $this->atlist) {
  107. foreach($this->atlist as $atuid => $atusername) {
  108. notification_add($atuid, 'at', 'at_message', array('from_id' => $this->thread['tid'], 'from_idtype' => 'at', 'buyerid' => $this->member['uid'], 'buyer' => $this->member['username'], 'tid' => $this->thread['tid'], 'subject' => $this->thread['subject'], 'pid' => $this->pid, 'message' => messagecutstr($this->param['message'], 150)));
  109. }
  110. set_atlist_cookie(array_keys($this->atlist));
  111. }
  112. }
  113. public function before_editpost($parameters) {
  114. if($this->group['allowat']) {
  115. $this->atlist = $atlist_tmp = $ateduids = array();
  116. $atnum = $maxselect = 0;
  117. foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($this->member['uid'], $this->thread['tid'], 'at') as $row) {
  118. $atnum ++;
  119. $ateduids[$row[uid]] = $row['uid'];
  120. }
  121. $maxselect = $this->group['allowat'] - $atnum;
  122. preg_match_all("/@([^\r\n]*?)\s/i", $parameters['message'].' ', $atlist_tmp);
  123. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $this->group['allowat']);
  124. if($maxselect > 0 && !empty($atlist_tmp)) {
  125. if(empty($this->setting['at_anyone'])) {
  126. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($this->member['uid'], $atlist_tmp) as $row) {
  127. if(!in_array($row['followuid'], $ateduids)) {
  128. $this->atlist[$row[followuid]] = $row['fusername'];
  129. }
  130. if(count($this->atlist) == $maxselect) {
  131. break;
  132. }
  133. }
  134. if(count($this->atlist) < $maxselect) {
  135. $query = C::t('home_friend')->fetch_all_by_uid_username($this->member['uid'], $atlist_tmp);
  136. foreach($query as $row) {
  137. if(!in_array($row['followuid'], $ateduids)) {
  138. $this->atlist[$row[fuid]] = $row['fusername'];
  139. }
  140. }
  141. }
  142. } else {
  143. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  144. if(!in_array($row['uid'], $ateduids)) {
  145. $this->atlist[$row[uid]] = $row['username'];
  146. }
  147. if(count($this->atlist) == $maxselect) {
  148. break;
  149. }
  150. }
  151. }
  152. if($this->atlist) {
  153. foreach($this->atlist as $atuid => $atusername) {
  154. $atsearch[] = "/@$atusername /i";
  155. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  156. }
  157. $parameters['message'] = preg_replace($atsearch, $atreplace, $parameters['message'].' ', 1);
  158. $parameters['message'] = substr($parameters['message'], 0, strlen($parameters['message']) - 1);
  159. }
  160. }
  161. }
  162. }
  163. public function after_editpost() {
  164. if($this->group['allowat'] && $this->atlist) {
  165. foreach($this->atlist as $atuid => $atusername) {
  166. notification_add($atuid, 'at', 'at_message', array('from_id' => $this->thread['tid'], 'from_idtype' => 'at', 'buyerid' => $this->member['uid'], 'buyer' => $this->member['username'], 'tid' => $this->thread['tid'], 'subject' => $this->thread['subject'], 'pid' => $this->post['pid'], 'message' => messagecutstr($this->param['message'], 150)));
  167. }
  168. set_atlist_cookie(array_keys($this->atlist));
  169. }
  170. }
  171. }
  172. ?>