processor.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. class CoreModuleProcessor extends WeModuleProcessor {
  8. public function respond() {
  9. $reply_type = $this->reply_type;
  10. $key = array_rand($reply_type);
  11. $type = $reply_type[$key];
  12. switch ($type) {
  13. case 'basic':
  14. $result = $this->basic_respond();
  15. return $this->respText($result);
  16. break;
  17. case 'images':
  18. $result = $this->image_respond();
  19. return $this->respImage($result);
  20. break;
  21. case 'music':
  22. $result = $this->music_respond();
  23. return $this->respMusic(array(
  24. 'Title' => $result['title'],
  25. 'Description' => $result['description'],
  26. 'MusicUrl' => $result['url'],
  27. 'HQMusicUrl' => $result['hqurl'],
  28. ));
  29. break;
  30. case 'news':
  31. $result = $this->news_respond();
  32. return $this->respNews($result);
  33. break;
  34. case 'voice':
  35. $result = $this->voice_respond();
  36. return $this->respVoice($result);
  37. break;
  38. case 'video':
  39. $result = $this->video_respond();
  40. return $this->respVideo(array(
  41. 'MediaId' => $result['mediaid'],
  42. 'Title' => $result['title'],
  43. 'Description' => $result['description'],
  44. ));
  45. break;
  46. case 'wxapp':
  47. $result = $this->wxapp_respond();
  48. return $this->respWxapp(array(
  49. 'Title' => $result['title'],
  50. 'Appid' => $result['appid'],
  51. 'PagePath' => $result['pagepath'],
  52. 'ThumbMediaId' => $result['mediaid'],
  53. ));
  54. break;
  55. }
  56. }
  57. private function basic_respond() {
  58. $rids = !is_array($this->rule) ? explode(',', $this->rule) : $this->rule;
  59. $reply = table('basic_reply')->where(array('rid IN' => $rids))->orderby('RAND()')->get();
  60. if (empty($reply)) {
  61. return false;
  62. }
  63. $reply['content'] = htmlspecialchars_decode($reply['content']);
  64. $reply['content'] = str_replace(array('<br>', '&nbsp;'), array("\n", ' '), $reply['content']);
  65. $reply['content'] = strip_tags($reply['content'], '<a>');
  66. return $reply['content'];
  67. }
  68. private function image_respond() {
  69. global $_W;
  70. $rid = $this->rule;
  71. $mediaid = table('images_reply')->where(array('rid' => $rid))->orderby('RAND()')->getcolumn('mediaid');
  72. if (empty($mediaid)) {
  73. return false;
  74. }
  75. return $mediaid;
  76. }
  77. private function music_respond() {
  78. global $_W;
  79. $rid = $this->rule;
  80. $item = table('music_reply')->where(array('rid' => $rid))->orderby('RAND()')->get();
  81. if (empty($item['id'])) {
  82. return false;
  83. }
  84. return $item;
  85. }
  86. private function news_respond() {
  87. global $_W;
  88. load()->model('material');
  89. $rid = $this->rule;
  90. $commends = table('news_reply')
  91. ->where(array('rid' => $rid, 'parent_id' => -1))
  92. ->orderby(array('displayorder' => 'DESC', 'id' => 'ASC'))
  93. ->limit(8)
  94. ->getall();
  95. if (empty($commends)) {
  96. $main = table('news_reply')
  97. ->where(array(
  98. 'rid' => $rid,
  99. 'parent_id' => 0
  100. ))
  101. ->orderby('RAND()')
  102. ->get();
  103. if (empty($main['id'])) {
  104. return false;
  105. }
  106. $commends = table('news_reply')
  107. ->where(array('id' => $main['id']))
  108. ->whereor(array('parent_id' => $main['id']))
  109. ->orderby(array(
  110. 'displayorder' => 'ASC',
  111. 'id' => 'ASC'
  112. ))
  113. ->limit(8)
  114. ->getall();
  115. }
  116. if (empty($commends)) {
  117. return false;
  118. }
  119. $news = array();
  120. if (!empty($commends[0]['media_id'])) {
  121. $news = material_build_reply($commends[0]['media_id']);
  122. }
  123. foreach ($commends as $key => $commend) {
  124. $row = array();
  125. if (!empty($commend['media_id'])) {
  126. if (empty($news[$key]['url'])) {
  127. $news[$key]['url'] = $this->createMobileUrl('detail', array('id' => $commend['id']));
  128. }
  129. } else {
  130. $row['title'] = $commend['title'];
  131. $row['description'] = $commend['description'];
  132. !empty($commend['thumb']) && $row['picurl'] = tomedia($commend['thumb']);
  133. $row['url'] = empty($commend['url']) ? $this->createMobileUrl('detail', array('id' => $commend['id'])) : $commend['url'];
  134. $news[] = $row;
  135. }
  136. }
  137. return $news;
  138. }
  139. private function voice_respond() {
  140. global $_W;
  141. $rid = $this->rule;
  142. $mediaid = table('voice_reply')
  143. ->where(array('rid' => $rid))
  144. ->orderby('RAND()')
  145. ->getcolumn('mediaid');
  146. if (empty($mediaid)) {
  147. return false;
  148. }
  149. return $mediaid;
  150. }
  151. private function video_respond() {
  152. global $_W;
  153. $rid = $this->rule;
  154. $item = table('video_reply')
  155. ->where(array('rid' => $rid))
  156. ->orderby('RAND()')
  157. ->get();
  158. if (empty($item)) {
  159. return false;
  160. }
  161. return $item;
  162. }
  163. private function wxapp_respond() {
  164. global $_W;
  165. $rid = $this->rule;
  166. $item = table('wxapp_reply')
  167. ->where(array('rid' => $rid))
  168. ->orderby('RAND()')
  169. ->get();
  170. if (empty($item)) {
  171. return false;
  172. }
  173. return $item;
  174. }
  175. }