PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/source/class/extend/extend_thread_allowat.php

https://github.com/jinbo51/DiscuzX
PHP | 181 lines | 163 code | 12 blank | 6 comment | 41 complexity | b4bcd71589d39612ed497726d468a909 MD5 | raw file
Possible License(s): BSD-3-Clause
  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 32746 2013-03-05 10:29:02Z liulanbo $
  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. }
  43. }
  44. }
  45. public function after_newthread() {
  46. if($this->group['allowat'] && $this->atlist) {
  47. foreach($this->atlist as $atuid => $atusername) {
  48. 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)));
  49. }
  50. set_atlist_cookie(array_keys($this->atlist));
  51. }
  52. }
  53. public function before_newreply($parameters) {
  54. if($this->group['allowat']) {
  55. $atlist_tmp = $ateduids = array();
  56. preg_match_all("/@([^\r\n]*?)\s/i", $parameters['message'].' ', $atlist_tmp);
  57. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $this->group['allowat']);
  58. $atnum = $maxselect = 0;
  59. foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($this->member['uid'], $this->thread['tid'], 'at') as $row) {
  60. $atnum ++;
  61. $ateduids[$row[uid]] = $row['uid'];
  62. }
  63. $maxselect = $this->group['allowat'] - $atnum;
  64. if($maxselect > 0 && !empty($atlist_tmp)) {
  65. $at_anyone = $this->setting['at_anyone'];
  66. if(empty($at_anyone)) {
  67. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($this->member['uid'], $atlist_tmp) as $row) {
  68. if(!in_array($row['followuid'], $ateduids)) {
  69. $this->atlist[$row[followuid]] = $row['fusername'];
  70. }
  71. if(count($this->atlist) == $maxselect) {
  72. break;
  73. }
  74. }
  75. if(count($this->atlist) < $maxselect) {
  76. $query = C::t('home_friend')->fetch_all_by_uid_username($this->member['uid'], $atlist_tmp);
  77. foreach($query as $row) {
  78. if(!in_array($row['followuid'], $ateduids)) {
  79. $this->atlist[$row[fuid]] = $row['fusername'];
  80. }
  81. }
  82. }
  83. } else {
  84. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  85. if(!in_array($row['uid'], $ateduids)) {
  86. $this->atlist[$row[uid]] = $row['username'];
  87. }
  88. if(count($this->atlist) == $maxselect) {
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. if($this->atlist) {
  95. foreach($this->atlist as $atuid => $atusername) {
  96. $atsearch[] = "/@$atusername /i";
  97. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  98. }
  99. $this->param['message'] = preg_replace($atsearch, $atreplace, $parameters['message'].' ', 1);
  100. }
  101. }
  102. }
  103. public function after_newreply() {
  104. if($this->group['allowat'] && $this->atlist) {
  105. foreach($this->atlist as $atuid => $atusername) {
  106. 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)));
  107. }
  108. set_atlist_cookie(array_keys($this->atlist));
  109. }
  110. }
  111. public function before_editpost($parameters) {
  112. if($this->group['allowat']) {
  113. $this->atlist = $atlist_tmp = $ateduids = array();
  114. $atnum = $maxselect = 0;
  115. foreach(C::t('home_notification')->fetch_all_by_authorid_fromid($this->member['uid'], $this->thread['tid'], 'at') as $row) {
  116. $atnum ++;
  117. $ateduids[$row[uid]] = $row['uid'];
  118. }
  119. $maxselect = $this->group['allowat'] - $atnum;
  120. preg_match_all("/@([^\r\n]*?)\s/i", $parameters['message'].' ', $atlist_tmp);
  121. $atlist_tmp = array_slice(array_unique($atlist_tmp[1]), 0, $this->group['allowat']);
  122. if($maxselect > 0 && !empty($atlist_tmp)) {
  123. if(empty($this->setting['at_anyone'])) {
  124. foreach(C::t('home_follow')->fetch_all_by_uid_fusername($this->member['uid'], $atlist_tmp) as $row) {
  125. if(!in_array($row['followuid'], $ateduids)) {
  126. $this->atlist[$row[followuid]] = $row['fusername'];
  127. }
  128. if(count($this->atlist) == $maxselect) {
  129. break;
  130. }
  131. }
  132. if(count($this->atlist) < $maxselect) {
  133. $query = C::t('home_friend')->fetch_all_by_uid_username($this->member['uid'], $atlist_tmp);
  134. foreach($query as $row) {
  135. if(!in_array($row['followuid'], $ateduids)) {
  136. $this->atlist[$row[fuid]] = $row['fusername'];
  137. }
  138. }
  139. }
  140. } else {
  141. foreach(C::t('common_member')->fetch_all_by_username($atlist_tmp) as $row) {
  142. if(!in_array($row['uid'], $ateduids)) {
  143. $this->atlist[$row[uid]] = $row['username'];
  144. }
  145. if(count($this->atlist) == $maxselect) {
  146. break;
  147. }
  148. }
  149. }
  150. if($this->atlist) {
  151. foreach($this->atlist as $atuid => $atusername) {
  152. $atsearch[] = "/@$atusername /i";
  153. $atreplace[] = "[url=home.php?mod=space&uid=$atuid]@{$atusername}[/url] ";
  154. }
  155. $parameters['message'] = preg_replace($atsearch, $atreplace, $parameters['message'].' ', 1);
  156. }
  157. }
  158. }
  159. }
  160. public function after_editpost() {
  161. if($this->group['allowat'] && $this->atlist) {
  162. foreach($this->atlist as $atuid => $atusername) {
  163. 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)));
  164. }
  165. set_atlist_cookie(array_keys($this->atlist));
  166. }
  167. }
  168. }
  169. ?>