人人商城

module.ctrl.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. load()->model('extension');
  8. load()->model('cloud');
  9. load()->model('cache');
  10. load()->model('module');
  11. load()->model('user');
  12. load()->model('account');
  13. load()->classs('account');
  14. load()->model('utility');
  15. $dos = array('filter', 'check', 'check_upgrade', 'get_upgrade_info', 'upgrade', 'install', 'installed', 'not_installed', 'uninstall', 'save_module_info', 'module_detail', 'change_receive_ban');
  16. $do = in_array($do, $dos) ? $do : 'installed';
  17. if ($_W['role'] != ACCOUNT_MANAGE_NAME_OWNER && $_W['role'] != ACCOUNT_MANAGE_NAME_MANAGER && $_W['role'] != ACCOUNT_MANAGE_NAME_FOUNDER) {
  18. itoast('无权限操作!', referer(), 'error');
  19. }
  20. if ($do == 'check') {
  21. load()->classs('account');
  22. $modulename = $_GPC['module_name'];
  23. $obj = WeUtility::createModuleReceiver($modulename);
  24. if (empty($obj)) {
  25. exit('error');
  26. }
  27. $obj->uniacid = $_W['uniacid'];
  28. $obj->acid = $_W['acid'];
  29. $obj->message = array(
  30. 'event' => 'subscribe'
  31. );
  32. if(method_exists($obj, 'receive')) {
  33. @$obj->receive();
  34. iajax(0);
  35. } else {
  36. iajax(1);
  37. }
  38. }
  39. if ($do == 'get_upgrade_info') {
  40. $module_name = trim($_GPC['name']);
  41. $module_info = module_fetch($module_name);
  42. $module = cloud_m_upgradeinfo($module_name);
  43. if (is_error($module)) {
  44. iajax(1, $module['message']);
  45. } else {
  46. iajax(0, $module, '');
  47. }
  48. }
  49. if ($do == 'check_upgrade') {
  50. $module_list = $_GPC['module_list']; if (!empty($module_list) && is_array($module_list)) {
  51. $module_list = pdo_getall('modules', array('name' => $module_list));
  52. } else {
  53. iajax(0, '');
  54. }
  55. $cloud_prepare_result = cloud_prepare();
  56. $cloud_m_query_module = cloud_m_query();
  57. if (is_error($cloud_m_query_module)) {
  58. $cloud_m_query_module = array();
  59. }
  60. foreach ($module_list as &$module) {
  61. $manifest = ext_module_manifest($module['name']);
  62. if (!empty($manifest)&& is_array($manifest)) {
  63. if (version_compare($module['version'], $manifest['application']['version']) == '-1') {
  64. $module['best_version'] = $manifest['application']['version'];
  65. $module['upgrade'] = true;
  66. } else {
  67. $module['upgrade'] = false;
  68. }
  69. $module['from'] = 'local';
  70. }
  71. if (empty($manifest)) {
  72. if (in_array($module['name'], array_keys($cloud_m_query_module))) {
  73. $cloud_m_info = $cloud_m_query_module[$module['name']];
  74. if (!empty($cloud_m_info['service_expiretime'])) {
  75. $module['service_expire'] = $cloud_m_info['service_expiretime'] > time() ? false : true;
  76. }
  77. $site_branch = $cloud_m_info['site_branch']['id'];
  78. if (empty($site_branch)) {
  79. $site_branch = $cloud_m_info['branch'];
  80. }
  81. $cloud_branch_version = $cloud_m_info['branches'][$site_branch]['version'];
  82. if (!empty($cloud_m_info['branches'])) {
  83. $best_branch_id = 0;
  84. foreach ($cloud_m_info['branches'] as $branch) {
  85. if ($best_branch_id == 0) {
  86. $best_branch_id = $branch['id'];
  87. } else {
  88. if ($branch['displayorder'] > $cloud_m_info['branches'][$best_branch_id]['displayorder']) {
  89. $best_branch_id = $branch['id'];
  90. }
  91. }
  92. }
  93. } else {
  94. $module['upgrade'] = false;
  95. continue;
  96. }
  97. $best_branch = $cloud_m_info['branches'][$best_branch_id];
  98. if (version_compare($module['version'], $cloud_branch_version) == -1 || ($cloud_m_info['displayorder'] < $best_branch['displayorder'] && !empty($cloud_m_info['version']))) {
  99. $module['upgrade'] = true;
  100. } else {
  101. $module['upgrade'] = false;
  102. }
  103. $module['from'] = 'cloud';
  104. }
  105. }
  106. }
  107. unset($module);
  108. iajax(0, $module_list, '');
  109. }
  110. if ($do == 'upgrade') {
  111. $points = ext_module_bindings();
  112. $module_name = addslashes($_GPC['module_name']);
  113. $module_exist = module_fetch($module_name);
  114. if (empty($module_exist)) {
  115. itoast('模块已经被卸载或是不存在!', '', 'error');
  116. }
  117. $manifest = ext_module_manifest($module_name);
  118. if (empty($manifest)) {
  119. $cloud_prepare = cloud_prepare();
  120. if (is_error($cloud_prepare)) {
  121. iajax(1, $cloud_prepare['message']);
  122. }
  123. $module_info = cloud_m_upgradeinfo($module_name);
  124. if (is_error($module_info)) {
  125. iajax(1, $module_info);
  126. }
  127. $uninstall_modules = module_get_all_unistalled('uninstalled');
  128. $upgrade_support_module = $uninstall_modules['modules'][$module_name]['upgrade_support'];
  129. if (!empty($_GPC['flag']) || $upgrade_support_module) {
  130. define('ONLINE_MODULE', true);
  131. $packet = cloud_m_build($module_name);
  132. $manifest = ext_module_manifest_parse($packet['manifest']);
  133. }
  134. }
  135. if (empty($manifest)) {
  136. itoast('模块安装配置文件不存在或是格式不正确!', '', 'error');
  137. }
  138. $check_manifest_result = manifest_check($module_name, $manifest);
  139. if (is_error($check_manifest_result)) {
  140. itoast($check_manifest_result['message'], '', 'error');
  141. }
  142. $module_path = IA_ROOT . '/addons/' . $module_name . '/';
  143. if (!file_exists($module_path . 'processor.php') && !file_exists($module_path . 'module.php') && !file_exists($module_path . 'receiver.php') && !file_exists($module_path . 'site.php')) {
  144. itoast('模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!', '', 'error');
  145. }
  146. if (!empty($manifest['platform']['plugin_list'])) {
  147. pdo_delete('modules_plugin', array('main_module' => $manifest['application']['identifie']));
  148. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  149. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  150. }
  151. }
  152. $module = ext_module_convert($manifest);
  153. unset($module['name'], $module['title']);
  154. $bindings = array_elements(array_keys($points), $module, false);
  155. foreach ($points as $point_name => $point_info) {
  156. unset($module[$point_name]);
  157. if (is_array($bindings[$point_name]) && !empty($bindings[$point_name])) {
  158. foreach ($bindings[$point_name] as $entry) {
  159. $entry['module'] = $manifest['application']['identifie'];
  160. $entry['entry'] = $point_name;
  161. if ($point_name == 'page' && !empty($wxapp_support)) {
  162. $entry['url'] = $entry['do'];
  163. $entry['do'] = '';
  164. }
  165. if ($entry['title'] && $entry['do']) {
  166. $not_delete_do[] = $entry['do'];
  167. $not_delete_title[] = $entry['title'];
  168. $module_binding = pdo_get('modules_bindings',array('module' => $manifest['application']['identifie'], 'entry' => $point_name, 'title' => $entry['title'], 'do' => $entry['do']));
  169. if (!empty($module_binding)) {
  170. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  171. continue;
  172. }
  173. } elseif ($entry['call']) {
  174. $not_delete_call[] = $entry['call'];
  175. $module_binding = pdo_get('modules_bindings',array('module' => $manifest['application']['identifie'], 'entry' => $point_name, 'call' => $entry['call']));
  176. if (!empty($module_binding)) {
  177. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  178. continue;
  179. }
  180. }
  181. pdo_insert('modules_bindings', $entry);
  182. }
  183. if (!empty($not_delete_do)) {
  184. pdo_query("DELETE FROM " . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND `call` = '' AND do NOT IN ('" . implode("','", $not_delete_do) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $point_name));
  185. unset($not_delete_do);
  186. }
  187. if (!empty($not_delete_title)) {
  188. pdo_query("DELETE FROM " . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND `call` = '' AND title NOT IN ('" . implode("','", $not_delete_title) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $point_name));
  189. unset($not_delete_title);
  190. }
  191. if (!empty($not_delete_call)) {
  192. pdo_query("DELETE FROM " . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND do = '' AND title = '' AND `call` NOT IN ('" . implode("','", $not_delete_call) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $point_name));
  193. unset($not_delete_call);
  194. }
  195. }
  196. }
  197. if (!empty($manifest['upgrade'])) {
  198. if (strexists($manifest['upgrade'], '.php')) {
  199. if (file_exists($module_path . $manifest['upgrade'])) {
  200. include_once $module_path . $manifest['upgrade'];
  201. if (ONLINE_MODULE) {
  202. unlink($module_path . $manifest['upgrade']);
  203. }
  204. }
  205. } else {
  206. pdo_run($manifest['upgrade']);
  207. }
  208. }
  209. if (ONLINE_MODULE) {
  210. if (strexists($manifest['uninstall'], '.php') && file_exists($module_path . $manifest['uninstall'])) {
  211. unlink($module_path . $manifest['uninstall']);
  212. }
  213. if (strexists($manifest['install'], '.php') && file_exists($module_path . $manifest['install'])) {
  214. unlink($module_path . $manifest['install']);
  215. }
  216. }
  217. $module['permissions'] = iserializer($module['permissions']);
  218. if (!empty($module_info['version']['cloud_setting'])) {
  219. $module['settings'] = 2;
  220. } else {
  221. $module['settings'] = empty($module['settings']) ? 0 : 1;
  222. }
  223. pdo_update('modules', $module, array('name' => $module_name));
  224. cache_build_account_modules();
  225. cache_build_uninstalled_module();
  226. cache_build_cloud_upgrade_module();
  227. if (!empty($module['subscribes'])) {
  228. ext_check_module_subscribe($module_name);
  229. }
  230. cache_delete('cloud:transtoken');
  231. cache_build_module_info($module_name);
  232. itoast('模块更新成功!', url('system/module', array('account_type' => ACCOUNT_TYPE)), 'success');
  233. }
  234. if ($do =='install') {
  235. $points = ext_module_bindings();
  236. $module_name = trim($_GPC['module_name']);
  237. $is_recycle_module = pdo_get('modules_recycle', array('modulename' => $module_name));
  238. if (empty($_W['isfounder'])) {
  239. itoast('您没有安装模块的权限', '', 'error');
  240. }
  241. $module_info = module_fetch($module_name);
  242. if (!empty($module_info)) {
  243. itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  244. }
  245. $manifest = ext_module_manifest($module_name);
  246. if (!empty($manifest)) {
  247. $result = cloud_m_prepare($module_name);
  248. if (is_error($result)) {
  249. itoast($result['message'], url('system/module/not_installed', array('account_type' => ACCOUNT_TYPE)), 'error');
  250. }
  251. } else {
  252. $result = cloud_prepare();
  253. if (is_error($result)) {
  254. itoast($result['message'], url('cloud/profile'), 'error');
  255. }
  256. $module_info = cloud_m_info($module_name);
  257. if (!is_error($module_info)) {
  258. if (empty($_GPC['flag'])) {
  259. header('location: ' . url('cloud/process', array('account_type' => ACCOUNT_TYPE, 'm' => $module_name)));
  260. exit;
  261. } else {
  262. define('ONLINE_MODULE', true);
  263. $packet = cloud_m_build($module_name);
  264. $manifest = ext_module_manifest_parse($packet['manifest']);
  265. }
  266. } else {
  267. itoast($module_info['message'], '', 'error');
  268. }
  269. }
  270. if (empty($manifest)) {
  271. itoast('模块安装配置文件不存在或是格式不正确,请刷新重试!', url('system/module/not_installed', array('account_type' => ACCOUNT_TYPE)), 'error');
  272. }
  273. if (!empty($manifest['platform']['main_module'])) {
  274. $plugin_exist = pdo_get('modules_plugin', array('main_module' => $manifest['platform']['main_module'], 'name' => $manifest['application']['identifie']));
  275. if (empty($plugin_exist)) {
  276. itoast('请先更新主模块后再安装插件', url('system/module/installed'), 'error');
  277. }
  278. }
  279. $check_manifest_result = manifest_check($module_name, $manifest);
  280. if (is_error($check_manifest_result)) {
  281. itoast($check_manifest_result['message'], '', 'error');
  282. }
  283. $module_path = IA_ROOT . '/addons/' . $module_name . '/';
  284. if (!file_exists($module_path . 'processor.php') && !file_exists($module_path . 'module.php') && !file_exists($module_path . 'receiver.php') && !file_exists($module_path . 'site.php')) {
  285. itoast('模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!', '', 'error');
  286. }
  287. $module = ext_module_convert($manifest);
  288. $module_group = uni_groups();
  289. if (!$_W['ispost'] || empty($_GPC['flag'])) {
  290. template('system/select-module-group');
  291. exit;
  292. }
  293. if (!empty($manifest['platform']['plugin_list'])) {
  294. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  295. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  296. }
  297. }
  298. $post_groups = $_GPC['group'];
  299. ext_module_clean($module_name);
  300. $bindings = array_elements(array_keys($points), $module, false);
  301. if (!empty($points)) {
  302. foreach ($points as $name => $point) {
  303. unset($module[$name]);
  304. if (is_array($bindings[$name]) && !empty($bindings[$name])) {
  305. foreach ($bindings[$name] as $entry) {
  306. $entry['module'] = $manifest['application']['identifie'];
  307. $entry['entry'] = $name;
  308. if ($name == 'page' && !empty($wxapp_support)) {
  309. $entry['url'] = $entry['do'];
  310. $entry['do'] = '';
  311. }
  312. pdo_insert('modules_bindings', $entry);
  313. }
  314. }
  315. }
  316. }
  317. $module['permissions'] = iserializer($module['permissions']);
  318. $module_subscribe_success = true;
  319. if (!empty($module['subscribes'])) {
  320. $subscribes = iunserializer($module['subscribes']);
  321. if (!empty($subscribes)) {
  322. $module_subscribe_success = ext_check_module_subscribe($module['name']);
  323. }
  324. }
  325. if (!empty($module_info['version']['cloud_setting'])) {
  326. $module['settings'] = 2;
  327. }
  328. $module['title_initial'] = get_first_pinyin($module['title']);
  329. if (strexists($manifest['install'], '.php')) {
  330. if (file_exists($module_path . $manifest['install'])) {
  331. include_once $module_path . $manifest['install'];
  332. if (ONLINE_MODULE) {
  333. unlink ($module_path . $manifest['install']);
  334. }
  335. }
  336. } else {
  337. pdo_run($manifest['install']);
  338. }
  339. if (pdo_insert('modules', $module)) {
  340. if (ONLINE_MODULE) {
  341. if (strexists($manifest['upgrade'], '.php') && file_exists($module_path . $manifest['upgrade'])) {
  342. unlink($module_path . $manifest['upgrade']);
  343. }
  344. if (strexists($manifest['uninstall'], '.php') && file_exists($module_path . $manifest['uninstall'])) {
  345. unlink($module_path . $manifest['uninstall']);
  346. }
  347. }
  348. if (defined('ONLINE_MODULE')) {
  349. ext_module_script_clean($module['name'], $manifest);
  350. }
  351. if ($_GPC['flag'] && !empty($post_groups) && $module['name']) {
  352. foreach ($post_groups as $groupid) {
  353. $group_info = pdo_get('uni_group', array('id' => intval($groupid)), array('id', 'name', 'modules'));
  354. if (empty($group_info)) {
  355. continue;
  356. }
  357. $group_info['modules'] = iunserializer($group_info['modules']);
  358. if (in_array($module['name'], $group_info['modules'])) {
  359. continue;
  360. }
  361. $group_info['modules'][] = $module['name'];
  362. $group_info['modules'] = iserializer($group_info['modules']);
  363. pdo_update('uni_group', $group_info, array('id' => $groupid));
  364. }
  365. }
  366. if (!empty($is_recycle_module)) {
  367. pdo_delete('modules_recycle', array('modulename' => $module_name));
  368. }
  369. cache_build_module_subscribe_type();
  370. cache_build_account_modules();
  371. cache_build_uninstalled_module();
  372. module_build_privileges();
  373. cache_build_module_info($module_name);
  374. if (empty($module_subscribe_success)) {
  375. itoast('模块安装成功!模块订阅消息有错误,系统已禁用该模块的订阅消息,详细信息请查看', url('system/module/module_detail', array('name' => $module['name'])), 'tips');
  376. } else {
  377. itoast('模块安装成功!', url('system/module', array('account_type' => ACCOUNT_TYPE)), 'success');
  378. }
  379. } else {
  380. itoast('模块安装失败, 请联系模块开发者!');
  381. }
  382. }
  383. if ($do == 'change_receive_ban') {
  384. $modulename = trim($_GPC['modulename']);
  385. $module_exist = module_fetch($modulename);
  386. if (empty($module_exist)) {
  387. iajax(1, '模块不存在', '');
  388. }
  389. if (!is_array($_W['setting']['module_receive_ban'])) {
  390. $_W['setting']['module_receive_ban'] = array();
  391. }
  392. if (in_array($modulename, $_W['setting']['module_receive_ban'])) {
  393. unset($_W['setting']['module_receive_ban'][$modulename]);
  394. } else {
  395. $_W['setting']['module_receive_ban'][$modulename] = $modulename;
  396. }
  397. setting_save($_W['setting']['module_receive_ban'], 'module_receive_ban');
  398. cache_build_module_subscribe_type();
  399. iajax(0, '');
  400. }
  401. if ($do == 'save_module_info') {
  402. $module_info = $_GPC['moduleinfo'];
  403. $type = trim($_GPC['type']);
  404. $module_name = trim($_GPC['modulename']);
  405. if (empty($module_name)) {
  406. iajax(1, '数据非法');
  407. }
  408. $module = module_fetch($module_name);
  409. if (empty($module)) {
  410. iajax(1, '数据非法');
  411. }
  412. $module_icon_map = array(
  413. 'logo' => array(
  414. 'filename' => 'icon-custom.jpg',
  415. 'url' => trim($_GPC['moduleinfo']['logo'])
  416. ),
  417. 'preview' => array(
  418. 'filename' => 'preview-custom.jpg',
  419. 'url' => trim($_GPC['moduleinfo']['preview'])
  420. ),
  421. );
  422. $module_field = array('title', 'ability', 'description');
  423. if (!in_array($type, array_keys($module_icon_map)) && !in_array($type, $module_field)) {
  424. iajax(1, '数据非法');
  425. }
  426. if (in_array($type, $module_field)) {
  427. $module_update = array($type => trim($module_info[$type]));
  428. $result = pdo_update('modules', $module_update, array('name' => $module_name));
  429. } else {
  430. $image_destination_url = IA_ROOT . "/addons/" . $module_name . '/' . $module_icon_map[$type]['filename'];
  431. $result = utility_image_rename($module_icon_map[$type]['url'], $image_destination_url);
  432. }
  433. cache_delete(cache_system_key("module_info:" . $module_name));
  434. if (!empty($result)) {
  435. iajax(0, '');
  436. }
  437. iajax(1, '更新失败');
  438. }
  439. if ($do == 'module_detail') {
  440. $_W['page']['title'] = '模块详情';
  441. $module_name = trim($_GPC['name']);
  442. $module_info = module_fetch($module_name);
  443. if (!empty($module_info['is_relation'])) {
  444. $type = intval($_GPC['type']);
  445. switch ($type) {
  446. case ACCOUNT_TYPE_OFFCIAL_NORMAL:
  447. case ACCOUNT_TYPE_OFFCIAL_AUTH:
  448. $module_info['relation_name'] = '小程序版';
  449. $module_info['account_type'] = 0;
  450. $module_info['type'] = ACCOUNT_TYPE_APP_NORMAL;
  451. break;
  452. default:
  453. $module_info['relation_name'] = '公众号版';
  454. $module_info['account_type'] = ACCOUNT_TYPE_OFFCIAL_NORMAL;
  455. $module_info['type'] = ACCOUNT_TYPE_OFFCIAL_NORMAL;
  456. break;
  457. }
  458. }
  459. if (file_exists(IA_ROOT.'/addons/'.$module_info['name'].'/preview-custom.jpg')) {
  460. $module_info['preview'] = tomedia(IA_ROOT.'/addons/'.$module_info['name'].'/preview-custom.jpg');
  461. } else {
  462. $module_info['preview'] = tomedia(IA_ROOT.'/addons/'.$module_info['name'].'/preview.jpg');
  463. }
  464. if (!empty($module_info['main_module'])) {
  465. $main_module = module_fetch($module_info['main_module']);
  466. }
  467. if (!empty($module_info['plugin_list'])) {
  468. foreach ($module_info['plugin_list'] as $key => &$plugin) {
  469. $plugin = module_fetch($plugin);
  470. if (empty($plugin)) {
  471. unset($module_info['plugin'][$name]);
  472. }
  473. }
  474. }
  475. unset($plugin);
  476. $module_group_list = pdo_getall('uni_group', array('uniacid' => 0));
  477. $module_group = array();
  478. if (!empty($module_group_list)) {
  479. foreach ($module_group_list as $group) {
  480. $group['modules'] = iunserializer($group['modules']);
  481. if (is_array($group['modules']) && in_array($module_name, $group['modules'])) {
  482. $module_group[] = $group;
  483. }
  484. }
  485. }
  486. $module_subscribes = array();
  487. $module['subscribes'] = iunserializer($module_info['subscribes']);
  488. if (!empty($module['subscribes'])) {
  489. foreach ($module['subscribes'] as $event) {
  490. if ($event == 'text' || $event == 'enter') {
  491. continue;
  492. }
  493. $module_subscribes = $module['subscribes'];
  494. }
  495. }
  496. $mtypes = ext_module_msg_types();
  497. $module_ban = $_W['setting']['module_receive_ban'];
  498. if (!is_array($module_ban)) {
  499. $module_ban = array();
  500. }
  501. $receive_ban = in_array($module_info['name'], $module_ban) ? 1 : 2;
  502. $modulename = $_GPC['modulename'];
  503. $pageindex = max(1, $_GPC['page']);
  504. $pagesize = 20;
  505. $use_module_account = array();
  506. $total = count($use_module_account);
  507. $use_module_account = array_slice($use_module_account, ($pageindex - 1) * $pagesize, $pagesize);
  508. $pager = pagination($total, $pageindex, $pagesize);
  509. }
  510. if ($do == 'uninstall') {
  511. $name = trim($_GPC['name']);
  512. $message = '';
  513. $module = module_fetch($name);
  514. if (!empty($module['plugin'])) {
  515. $plugin_list = module_get_plugin_list($module['name']);
  516. if (!empty($plugin_list) && is_array($plugin_list)) {
  517. $message .= '删除' . $module['title'] . '并删除' . $module['title'] . '包含插件<ul>';
  518. foreach ($plugin_list as $plugin) {
  519. $message .= "<li>{$plugin['title']}</li>";
  520. }
  521. unset($plugin);
  522. $message .= '</ul>';
  523. }
  524. }
  525. if (!isset($_GPC['confirm'])) {
  526. if ($module['isrulefields']) {
  527. $message .= '是否删除相关规则和统计分析数据<div><a class="btn btn-primary" style="width:80px;" href="' . url('system/module/uninstall', array('name' => $name, 'confirm' => 1)) . '">是</a> &nbsp;&nbsp;<a class="btn btn-default" style="width:80px;" href="' . url('system/module/uninstall', array('account_type' => ACCOUNT_TYPE, 'name' => $name, 'confirm' => 0)) . '">否</a></div>';
  528. } elseif (!empty($plugin_list)) {
  529. $message .= "<a href=" . url('system/module/uninstall', array('name' => $name,'confirm' => 0)) . " class='btn btn-info'>继续删除</a>";
  530. }
  531. if (!empty($message)) {
  532. itoast($message, '', 'tips');
  533. }
  534. }
  535. if (!empty($plugin_list) && is_array($plugin_list)) {
  536. foreach ($plugin_list as $plugin) {
  537. module_uninstall($plugin['name']);
  538. }
  539. }
  540. $uninstall_result = module_uninstall($module['name'], $_GPC['confirm'] == 1);
  541. if (is_error($uninstall_result)) {
  542. itoast($uninstall_result['message'], url('system/module'), 'error');
  543. }
  544. itoast('模块已放入回收站!', url('system/module', array('account_type' => ACCOUNT_TYPE)), 'success');
  545. }
  546. if ($do == 'installed') {
  547. $_W['page']['title'] = '应用列表';
  548. $uninstalled_module = module_get_all_unistalled('uninstalled');
  549. $total_uninstalled = $uninstalled_module['module_count'];
  550. $pageindex = max($_GPC['page'], 1);
  551. $pagesize = 20;
  552. $letter = $_GPC['letter'];
  553. $title = $_GPC['title'];
  554. $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  555. $module_list = $all_modules = user_modules($_W['uid']);
  556. if (!empty($module_list)) {
  557. foreach ($module_list as $key => &$module) {
  558. if (!empty($module['issystem']) || (ACCOUNT_TYPE == ACCOUNT_TYPE_APP_NORMAL && $module['wxapp_support'] != 2) || (ACCOUNT_TYPE == ACCOUNT_TYPE_OFFCIAL_NORMAL && $module['app_support'] != 2)) {
  559. unset($module_list[$key]);
  560. }
  561. if (!empty($letter) && strlen($letter) == 1) {
  562. if ($module['title_initial'] != $letter){
  563. unset($module_list[$key]);
  564. }
  565. }
  566. if (!empty($title) && !strexists($module['title'], $title)) {
  567. unset($module_list[$key]);
  568. }
  569. }
  570. unset($module);
  571. }
  572. $total = count($module_list);
  573. if ($total > 0){
  574. $module_list = array_slice($module_list, ($pageindex - 1) * $pagesize, $pagesize);
  575. }
  576. $pager = pagination($total, $pageindex, $pagesize);
  577. }
  578. if ($do == 'not_installed') {
  579. if (empty($_W['isfounder'])) {
  580. itoast('非法访问!', referer(), 'info');
  581. }
  582. $_W['page']['title'] = '安装模块 - 模块 - 扩展';
  583. $status = $_GPC['status'] == 'recycle'? 'recycle' : 'uninstalled';
  584. $letters = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  585. $title = $_GPC['title'];
  586. $letter = $_GPC['letter'];
  587. $pageindex = max($_GPC['page'], 1);
  588. $pagesize = 20;
  589. $uninstallModules = module_get_all_unistalled($status);
  590. $total_uninstalled = $uninstallModules['module_count'];
  591. $uninstallModules = (array)$uninstallModules['modules'];
  592. if (!empty($uninstallModules)) {
  593. foreach($uninstallModules as $name => &$module) {
  594. if (!empty($letter) && strlen($letter) == 1) {
  595. $first_char = get_first_pinyin($module['title']);
  596. if ($letter != $first_char) {
  597. unset($uninstallModules[$name]);
  598. continue;
  599. }
  600. }
  601. if (!empty($title)) {
  602. if (!strexists($module['title'], $title)) {
  603. unset($uninstallModules[$name]);
  604. continue;
  605. }
  606. }
  607. if (file_exists(IA_ROOT.'/addons/'.$module['name'].'/icon-custom.jpg')) {
  608. $module['logo'] = tomedia(IA_ROOT.'/addons/'.$module['name'].'/icon-custom.jpg');
  609. } elseif (file_exists(IA_ROOT.'/addons/'.$module['name'].'/icon.jpg')) {
  610. $module['logo'] = tomedia(IA_ROOT.'/addons/'.$module['name'].'/icon.jpg');
  611. } else {
  612. $module['logo'] = tomedia($module['thumb']);
  613. }
  614. if (!empty($module['main_module'])) {
  615. $main_module_installed = module_fetch($module['main_module']);
  616. if ($main_module_installed) {
  617. $module['main_module_logo'] = $main_module_installed['logo'];
  618. } else {
  619. if ($module['from'] == 'cloud') {
  620. $module['main_module_logo'] = tomedia($uninstallModules[$module['main_module']]['thumb']);
  621. } else {
  622. if (file_exists(IA_ROOT.'/addons/'.$module['main_module'].'/icon-custom.jpg')) {
  623. $module['main_module_logo'] = tomedia(IA_ROOT.'/addons/'.$module['main_module'].'/icon-custom.jpg');
  624. } elseif (file_exists(IA_ROOT.'/addons/'.$module['main_module'].'/icon.jpg')) {
  625. $module['main_module_logo'] = tomedia(IA_ROOT.'/addons/'.$module['main_module'].'/icon.jpg');
  626. }
  627. }
  628. }
  629. }
  630. }
  631. }
  632. $total = count($uninstallModules);
  633. $uninstallModules = array_slice($uninstallModules, ($pageindex - 1)*$pagesize, $pagesize);
  634. $pager = pagination($total, $pageindex, $pagesize);
  635. }
  636. if ($do == 'filter') {
  637. $pageindex = max($_GPC['pageindex'], 1);
  638. $pagesize = 20;
  639. $condition = $_GPC['condition'];
  640. $module_list = user_modules($_W['uid']);
  641. $upgrade_modules = module_filter_upgrade(array_keys($module_list));
  642. $modules = array();
  643. if (!empty($module_list) && is_array($module_list)) {
  644. $empty_condition = empty($condition['new_branch']) && empty($condition['upgrade_branch']);
  645. foreach ($module_list as $module) {
  646. $new_branch_module = !empty($condition['new_branch']) && $upgrade_modules[$module['name']]['new_branch'];
  647. $upgrade_branch_module = !empty($condition['upgrade_branch']) && $upgrade_modules[$module['name']]['upgrade_branch'];
  648. if (($empty_condition && $module['issystem'] != 1) || $new_branch_module || $upgrade_branch_module) {
  649. $modules[$module['name']] = $module;
  650. $modules[$module['name']]['upgrade'] = $upgrade_modules[$module['name']]['upgrade'];
  651. $modules[$module['name']]['new_branch'] = $upgrade_modules[$module['name']]['new_branch'];
  652. $modules[$module['name']]['upgrade_branch'] = $upgrade_modules[$module['name']]['upgrade_branch'];
  653. $modules[$module['name']]['from'] = $upgrade_modules[$module['name']]['from'];
  654. }
  655. }
  656. }
  657. $total = count($modules);
  658. $modules = array_slice($modules, ($pageindex - 1) * $pagesize, $pagesize);
  659. $pager = pagination($total, $pageindex, $pagesize, '', array('before' => 5, 'after' => 4,'ajaxcallback' => true, 'callbackfuncname' => 'filter'));
  660. iajax(0, array('modules' => $modules, 'pager' => $pager));
  661. }
  662. template('system/module' . ACCOUNT_TYPE_TEMPLATE);