人人商城

processor.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. }
  47. }
  48. private function basic_respond() {
  49. $sql = "SELECT * FROM " . tablename('basic_reply') . " WHERE `rid` IN ({$this->rule}) ORDER BY RAND() LIMIT 1";
  50. $reply = pdo_fetch($sql);
  51. if (empty($reply)) {
  52. return false;
  53. }
  54. $reply['content'] = htmlspecialchars_decode($reply['content']);
  55. $reply['content'] = str_replace(array('<br>', '&nbsp;'), array("\n", ' '), $reply['content']);
  56. $reply['content'] = strip_tags($reply['content'], '<a>');
  57. return $reply['content'];
  58. }
  59. private function image_respond() {
  60. global $_W;
  61. $rid = $this->rule;
  62. $sql = "SELECT `mediaid` FROM " . tablename('images_reply') . " WHERE `rid`=:rid ORDER BY RAND()";
  63. $mediaid = pdo_fetchcolumn($sql, array(':rid' => $rid));
  64. if (empty($mediaid)) {
  65. return false;
  66. }
  67. return $mediaid;
  68. }
  69. private function music_respond() {
  70. global $_W;
  71. $rid = $this->rule;
  72. $sql = "SELECT * FROM " . tablename('music_reply') . " WHERE `rid`=:rid ORDER BY RAND()";
  73. $item = pdo_fetch($sql, array(':rid' => $rid));
  74. if (empty($item['id'])) {
  75. return false;
  76. }
  77. return $item;
  78. }
  79. private function news_respond() {
  80. global $_W;
  81. load()->model('material');
  82. $rid = $this->rule;
  83. $sql = "SELECT * FROM " . tablename('news_reply') . " WHERE rid = :id AND parent_id = -1 ORDER BY displayorder DESC, id ASC LIMIT 8";
  84. $commends = pdo_fetchall($sql, array(':id' => $rid));
  85. if (empty($commends)) {
  86. $sql = "SELECT * FROM " . tablename('news_reply') . " WHERE rid = :id AND parent_id = 0 ORDER BY RAND()";
  87. $main = pdo_fetch($sql, array(':id' => $rid));
  88. if(empty($main['id'])) {
  89. return false;
  90. }
  91. $sql = "SELECT * FROM " . tablename('news_reply') . " WHERE id = :id OR parent_id = :parent_id ORDER BY displayorder ASC, id ASC LIMIT 8";
  92. $commends = pdo_fetchall($sql, array(':id'=>$main['id'], ':parent_id'=>$main['id']));
  93. }
  94. if(empty($commends)) {
  95. return false;
  96. }
  97. $news = array();
  98. if (!empty($commends[0]['media_id'])) {
  99. $news = material_build_reply($commends[0]['media_id']);
  100. }
  101. foreach($commends as $key => $commend) {
  102. $row = array();
  103. if (!empty($commend['media_id'])) {
  104. if (empty($news[$key]['url'])) {
  105. $news[$key]['url'] = $this->createMobileUrl('detail', array('id' => $commend['id']));
  106. }
  107. } else {
  108. $row['title'] = $commend['title'];
  109. $row['description'] = $commend['description'];
  110. !empty($commend['thumb']) && $row['picurl'] = tomedia($commend['thumb']);
  111. $row['url'] = empty($commend['url']) ? $this->createMobileUrl('detail', array('id' => $commend['id'])) : $commend['url'];
  112. $news[] = $row;
  113. }
  114. }
  115. return $news;
  116. }
  117. private function voice_respond() {
  118. global $_W;
  119. $rid = $this->rule;
  120. $sql = "SELECT `mediaid` FROM " . tablename('voice_reply') . " WHERE `rid`=:rid ORDER BY RAND()";
  121. $mediaid = pdo_fetchcolumn($sql, array(':rid' => $rid));
  122. if (empty($mediaid)) {
  123. return false;
  124. }
  125. return $mediaid;
  126. }
  127. private function video_respond() {
  128. global $_W;
  129. $rid = $this->rule;
  130. $sql = "SELECT * FROM " . tablename('video_reply') . " WHERE `rid`=:rid ORDER BY RAND()";
  131. $item = pdo_fetch($sql, array(':rid' => $rid));
  132. if (empty($item)) {
  133. return false;
  134. }
  135. return $item;
  136. }
  137. }