人人商城

module.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 CoreModule extends WeModule {
  8. public $modules = array('basic', 'news', 'image', 'music', 'voice', 'video', 'wxcard', 'keyword', 'module');
  9. public $tablename = array(
  10. 'basic' => 'basic_reply',
  11. 'news' => 'news_reply',
  12. 'image' => 'images_reply',
  13. 'music' => 'music_reply',
  14. 'voice' => 'voice_reply',
  15. 'video' => 'video_reply',
  16. 'wxcard' => 'wxcard_reply',
  17. 'keyword' => 'basic_reply'
  18. );
  19. private $options = array(
  20. 'basic' => true,
  21. 'news' => true,
  22. 'image' => true,
  23. 'music' => true,
  24. 'voice' => true,
  25. 'video' => true,
  26. 'wxcard' => true,
  27. 'keyword' => true,
  28. 'module' => true,
  29. );
  30. private $replies = array();
  31. public function fieldsFormDisplay($rid = 0, $option = array()) {
  32. global $_GPC, $_W, $setting_keyword;
  33. load()->model('material');
  34. load()->model('reply');
  35. $replies = array();
  36. switch($_GPC['a']) {
  37. case 'mass':
  38. if (!empty($rid) && $rid > 0) {
  39. $isexists = pdo_get('mc_mass_record', array('id' => $rid), array('media_id', 'msgtype'));
  40. }
  41. if (!empty($isexists['media_id']) && !empty($isexists['msgtype'])) {
  42. $wechat_attachment = material_get($isexists['media_id']);
  43. switch ($isexists['msgtype']) {
  44. case 'news':
  45. if(!empty($wechat_attachment['news'])) {
  46. foreach ($wechat_attachment['news'] as &$item) {
  47. $item['thumb_url'] = tomedia($item['thumb_url']);
  48. $item['media_id'] = $isexists['media_id'];
  49. $item['attach_id'] = $item['attach_id'];
  50. $item['perm'] = $wechat_attachment['model'];
  51. }
  52. unset($item);
  53. }
  54. $replies['news'] = $wechat_attachment['news'];
  55. break;
  56. case 'image':
  57. $replies['image'][0]['img_url'] = tomedia($wechat_attachment['attachment'], true);
  58. $replies['image'][0]['mediaid'] = $isexists['media_id'];
  59. break;
  60. case 'voice':
  61. $replies['voice'][0]['title'] = $wechat_attachment['filename'];
  62. $replies['voice'][0]['mediaid'] = $isexists['media_id'];
  63. break;
  64. case 'video':
  65. $replies['video'][0] = iunserializer($wechat_attachment['tag']);
  66. $replies['video'][0]['mediaid'] = $isexists['media_id'];
  67. break;
  68. }
  69. }
  70. break;
  71. default:
  72. if (!empty($rid)) {
  73. $rule_rid = $rid;
  74. if (in_array($_GPC['m'], array('welcome', 'default'))) {
  75. $rule_rid = pdo_getcolumn('rule_keyword', array('rid' => $rid), 'rid');
  76. }
  77. $isexists = reply_single($rule_rid);
  78. }
  79. if ($_GPC['m'] == 'special') {
  80. $default_setting = uni_setting_load('default_message', $_W['uniacid']);
  81. $default_setting = $default_setting['default_message'] ? $default_setting['default_message'] : array();
  82. $reply_type = $default_setting[$_GPC['type']]['type'];
  83. if (empty($reply_type)) {
  84. if (!empty($default_setting[$_GPC['type']]['keyword'])) {
  85. $reply_type = 'keyword';
  86. }
  87. if (!empty($default_setting[$_GPC['type']]['module'])) {
  88. $reply_type = 'module';
  89. }
  90. if (empty($reply_type)) {
  91. break;
  92. }
  93. }
  94. if ($reply_type == 'module') {
  95. $replies['module'][0]['name'] = $default_setting[$_GPC['type']]['module'];
  96. $module_info = pdo_get('modules', array('name' => $default_setting[$_GPC['type']]['module']));
  97. $replies['module'][0]['title'] = $module_info['title'];
  98. if (file_exists(IA_ROOT. "/addons/". $module_info['name']. "/custom-icon.jpg")) {
  99. $replies['module'][0]['icon'] = "../addons/". $module_info['name']. "/custom-icon.jgp";
  100. } else {
  101. $replies['module'][0]['icon'] = "../addons/". $module_info['name']. "/icon.jpg";
  102. }
  103. } else {
  104. $replies['keyword'][0]['name'] = $isexists['name'];
  105. $replies['keyword'][0]['content'] = $setting_keyword;
  106. $replies['keyword'][0]['rid'] = $rid;
  107. }
  108. break;
  109. }
  110. if (!empty($isexists)) {
  111. $module = $isexists['module'];
  112. $module = $module == 'images' ? 'image' : $module;
  113. if ($_GPC['a'] == 'reply' && (!empty($_GPC['m']) && $_GPC['m'] == 'keyword')) {
  114. foreach ($this->tablename as $key => $tablename) {
  115. if ($key != 'keyword') {
  116. $replies[$key] = pdo_fetchall("SELECT * FROM ".tablename($tablename)." WHERE rid = :rid ORDER BY `id`", array(':rid' => $rid));
  117. switch ($key) {
  118. case 'image':
  119. foreach ($replies[$key] as &$img_value) {
  120. $img = pdo_get('wechat_attachment', array('media_id' => $img_value['mediaid']), array('attachment'));
  121. $img_value['img_url'] = tomedia($img['attachment'], true);
  122. }
  123. unset($img_value);
  124. break;
  125. case 'news' :
  126. foreach ($replies[$key] as &$news_value) {
  127. if (!empty($news_value) && !empty($news_value['media_id'])) {
  128. $news_material = material_get($news_value['media_id']);
  129. if (!is_error($news_material)) {
  130. $news_value['attach_id'] = $news_material['id'];
  131. $news_value['model'] = $news_material['model'];
  132. $news_value['description'] = $news_material['news'][0]['digest'];
  133. $news_value['thumb'] = tomedia($news_material['news'][0]['thumb_url']);
  134. }
  135. } else {
  136. $news_value['thumb'] = tomedia($news_value['thumb']);
  137. }
  138. }
  139. unset($news_value);
  140. break;
  141. case 'video' :
  142. foreach ($replies[$key] as &$video_value) {
  143. $video_material = material_get($video_value['mediaid']);
  144. $video_value['filename'] = $video_material['filename'];
  145. }
  146. unset($video_value);
  147. break;
  148. }
  149. }
  150. }
  151. } else {
  152. $replies['keyword'][0]['name'] = $isexists['name'];
  153. $replies['keyword'][0]['rid'] = $rid;
  154. $replies['keyword'][0]['content'] = $setting_keyword;
  155. }
  156. }
  157. break;
  158. }
  159. if(!is_array($option)) {
  160. $option = array();
  161. }
  162. $options = array_merge($this->options, $option);
  163. include $this->template('display');
  164. }
  165. public function fieldsFormValidate($rid = 0) {
  166. global $_GPC;
  167. $ifEmpty = 1;
  168. $reply = '';
  169. foreach ($this->modules as $key => $value) {
  170. if(trim($_GPC['reply']['reply_'.$value]) != '') {
  171. $ifEmpty = 0;
  172. }
  173. if( ($value == 'music' || $value == 'video' || $value == 'wxcard' || $value == 'news') && !empty($_GPC['reply']['reply_'.$value])) {
  174. $reply = ltrim($_GPC['reply']['reply_'.$value], '{');
  175. $reply = rtrim($reply, '}');
  176. $reply = explode('},{', $reply);
  177. foreach ($reply as &$val) {
  178. $val = htmlspecialchars_decode('{'.$val.'}');
  179. }
  180. $this->replies[$value] = $reply;
  181. }else {
  182. $this->replies[$value] = htmlspecialchars_decode($_GPC['reply']['reply_'.$value], ENT_QUOTES);
  183. }
  184. }
  185. if($ifEmpty) {
  186. return error(1, '必须填写有效的回复内容.');
  187. }
  188. return '';
  189. }
  190. public function fieldsFormSubmit($rid = 0) {
  191. global $_GPC, $_W;
  192. $delsql = '';
  193. foreach ($this->modules as $k => $val) {
  194. $tablename = $this->tablename[$val];
  195. if (!empty($tablename)) {
  196. pdo_delete($tablename, array('rid' => $rid));
  197. }
  198. }
  199. foreach ($this->modules as $val) {
  200. $replies = array();
  201. $tablename = $this->tablename[$val];
  202. if($this->replies[$val]) {
  203. if(is_array($this->replies[$val])) {
  204. foreach ($this->replies[$val] as $value) {
  205. $replies[] = json_decode($value, true);
  206. }
  207. }else {
  208. $replies = explode(',', $this->replies[$val]);
  209. foreach ($replies as &$v) {
  210. $v = json_decode($v);
  211. }
  212. }
  213. }
  214. switch ($val) {
  215. case 'basic':
  216. if(!empty($replies)) {
  217. foreach($replies as $reply) {
  218. pdo_insert($tablename, array('rid' => $rid, 'content' => $reply));
  219. }
  220. }
  221. break;
  222. case 'news':
  223. if(!empty($replies)) {
  224. $parent_id = 0;
  225. $attach_id = 0;
  226. foreach ($replies as $k=>$reply) {
  227. if (!empty($attach_id) && $reply['attach_id'] == $attach_id) {
  228. $reply['parent_id'] = $parent_id;
  229. }
  230. if ($reply['model'] == 'local') {
  231. $reply['mediaid'] = $reply['attach_id'];
  232. }
  233. pdo_insert ($tablename, array ('rid' => $rid, 'parent_id' => $reply['parent_id'], 'title' => $reply['title'], 'thumb' => tomedia($reply['thumb']), 'createtime' => $reply['createtime'], 'media_id' => $reply['mediaid'], 'displayorder' => $reply['displayorder'], 'description' => $reply['description'], 'url' => $reply['url']));
  234. if (empty($attach_id) || $reply['attach_id'] != $attach_id) {
  235. $parent_id = pdo_insertid();
  236. }
  237. $attach_id = $reply['attach_id'] ? $reply['attach_id'] : 0;
  238. }
  239. }
  240. break;
  241. case 'image':
  242. if(!empty($replies)) {
  243. foreach ($replies as $reply) {
  244. pdo_insert($tablename, array('rid' => $rid, 'mediaid' => $reply, 'createtime' => time()));
  245. }
  246. }
  247. break;
  248. case 'music':
  249. if(!empty($replies)) {
  250. foreach ($replies as $reply) {
  251. pdo_insert($tablename, array('rid' => $rid, 'title' => $reply['title'], 'url' => $reply['url'], 'hqurl' => $reply['hqurl'], 'description' => $reply['description']));
  252. }
  253. }
  254. break;
  255. case 'voice':
  256. if(!empty($replies)) {
  257. foreach ($replies as $reply) {
  258. pdo_insert($tablename, array('rid' => $rid, 'mediaid' => $reply, 'createtime' => time()));
  259. }
  260. }
  261. break;
  262. case 'video':
  263. if(!empty($replies)) {
  264. foreach ($replies as $reply) {
  265. pdo_insert($tablename, array('rid' => $rid, 'mediaid' => $reply['mediaid'], 'title' => $reply['title'], 'description' => $reply['description'], 'createtime' => time()));
  266. }
  267. }
  268. break;
  269. case 'wxcard':
  270. if(!empty($replies)) {
  271. foreach ($replies as $reply) {
  272. pdo_insert($tablename, array('rid' => $rid, 'title' => $reply['title'], 'card_id' => $reply['mediaid'], 'cid' => $reply['cid'], 'brand_name' => $reply['brandname'], 'logo_url' => $reply['logo_url'], 'success' => $reply['success'], 'error' => $reply['error']));
  273. }
  274. }
  275. break;
  276. }
  277. }
  278. return true;
  279. }
  280. public function ruleDeleted($rid = 0) {
  281. $reply_modules = array("basic", "news", "music", "images", "voice", "video", "wxcard");
  282. foreach($this->tablename as $tablename) {
  283. pdo_delete($tablename, array('rid' => $rid));
  284. }
  285. }
  286. }