人人商城

manage-system.ctrl.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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()->object('cloudapi');
  14. load()->model('utility');
  15. load()->func('db');
  16. $dos = array('subscribe', 'check_subscribe', 'check_upgrade', 'get_upgrade_info', 'upgrade',
  17. 'install', 'installed', 'not_installed', 'uninstall', 'save_module_info', 'module_detail',
  18. 'change_receive_ban', 'install_success', 'set_site_welcome_module',
  19. 'founder_update_modules', 'recycle', 'recycle_post',
  20. );
  21. $do = in_array($do, $dos) ? $do : 'installed';
  22. if (user_is_vice_founder() && !empty($_GPC['system_welcome'])){
  23. itoast('无权限操作!');
  24. }
  25. if ($do == 'set_site_welcome_module') {
  26. if (!$_W['isfounder']) {
  27. iajax(1, '非法操作');
  28. }
  29. if (!empty($_GPC['name'])) {
  30. $site = WeUtility::createModuleSystemWelcome($_GPC['name']);
  31. if (!method_exists($site, 'systemWelcomeDisplay')) {
  32. iajax(1, '应用未实现系统首页功能!');
  33. }
  34. }
  35. setting_save(trim($_GPC['name']), 'site_welcome_module');
  36. iajax(0);
  37. }
  38. if ($do == 'subscribe') {
  39. $module_uninstall_total = module_uninstall_total($module_support);
  40. $module_list = user_modules($_W['uid']);
  41. $subscribe_type = ext_module_msg_types();
  42. $subscribe_module = array();
  43. $receive_ban = $_W['setting']['module_receive_ban'];
  44. if (is_array($module_list) && !empty($module_list)) {
  45. foreach ($module_list as $module) {
  46. if (!empty($module['subscribes']) && is_array($module['subscribes'])) {
  47. $subscribe_module[$module['name']]['subscribe'] = $module['subscribes'];
  48. $subscribe_module[$module['name']]['title'] = $module['title'];
  49. $subscribe_module[$module['name']]['name'] = $module['name'];
  50. $subscribe_module[$module['name']]['subscribe_success'] = 2;
  51. $subscribe_module[$module['name']]['receive_ban'] = in_array($module['name'], $receive_ban) ? 1 : 0;
  52. }
  53. }
  54. }
  55. }
  56. if ($do == 'check_subscribe') {
  57. $module = module_fetch($_GPC['module_name']);
  58. if (empty($module)) {
  59. iajax(1);
  60. }
  61. $obj = WeUtility::createModuleReceiver($module['name']);
  62. if (empty($obj)) {
  63. iajax(1);
  64. }
  65. $obj->uniacid = $_W['uniacid'];
  66. $obj->acid = $_W['acid'];
  67. $obj->message = array(
  68. 'event' => 'subscribe'
  69. );
  70. if(method_exists($obj, 'receive')) {
  71. @$obj->receive();
  72. iajax(0);
  73. } else {
  74. iajax(1);
  75. }
  76. }
  77. if ($do == 'get_upgrade_info') {
  78. $modulename = trim($_GPC['name']);
  79. $module = module_fetch($modulename);
  80. if (empty($module)) {
  81. iajax(1, '模块不存在!');
  82. }
  83. $manifest = ext_module_manifest($modulename);
  84. $manifest_cloud = cloud_m_upgradeinfo($modulename);
  85. if (is_error($manifest_cloud)) {
  86. iajax(1, $manifest_cloud['message']);
  87. }
  88. $result = array(
  89. 'name' => $modulename,
  90. 'upgrade' => $manifest_cloud['upgrade'],
  91. 'site_branch' => $manifest_cloud['site_branch'],
  92. 'new_branch' => $manifest_cloud['new_branch'],
  93. 'branches' => $manifest_cloud['branches'],
  94. 'from' => 'cloud',
  95. 'id' => $manifest_cloud['id'],
  96. );
  97. if (!empty($manifest) && version_compare($manifest['application']['version'], $manifest_cloud['version']['version'], '>')) {
  98. $result = array(
  99. 'name' => $modulename,
  100. 'upgrade' => true,
  101. 'site_branch' => array(),
  102. 'branches' => array(),
  103. 'new_branch' => false,
  104. 'from' => 'local',
  105. 'best_version' => $manifest['application']['version'],
  106. );
  107. }
  108. iajax(0, $result);
  109. }
  110. if ($do == 'check_upgrade') {
  111. $module_upgrade = module_upgrade_info();
  112. cache_build_uninstalled_module();
  113. iajax(0, $module_upgrade);
  114. }
  115. if ($do == 'upgrade') {
  116. $module_name = $_GPC['module_name'];
  117. $module = module_fetch($module_name);
  118. if (empty($module)) {
  119. itoast('模块已经被卸载或是不存在!', '', 'error');
  120. }
  121. $manifest = ext_module_manifest($module_name);
  122. if (empty($manifest)) {
  123. $cloud_prepare = cloud_prepare();
  124. if (is_error($cloud_prepare)) {
  125. iajax(1, $cloud_prepare['message']);
  126. }
  127. $module_info = cloud_m_upgradeinfo($module_name);
  128. if (is_error($module_info)) {
  129. iajax(1, $module_info);
  130. }
  131. if (!empty($_GPC['flag'])) {
  132. define('ONLINE_MODULE', true);
  133. $packet = cloud_m_build($module_name);
  134. $manifest = ext_module_manifest_parse($packet['manifest']);
  135. }
  136. }
  137. if (empty($manifest)) {
  138. itoast('模块安装配置文件不存在或是格式不正确!', '', 'error');
  139. }
  140. $check_manifest_result = ext_manifest_check($module_name, $manifest);
  141. if (is_error($check_manifest_result)) {
  142. itoast($check_manifest_result['message'], '', 'error');
  143. }
  144. $check_file_result = ext_file_check($module_name, $manifest);
  145. if (is_error($check_file_result)) {
  146. itoast($check_file_result['message'], '', 'error');
  147. }
  148. if (!empty($manifest['platform']['plugin_list'])) {
  149. pdo_delete('modules_plugin', array('main_module' => $manifest['application']['identifie']));
  150. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  151. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  152. }
  153. }
  154. $module_upgrade = ext_module_convert($manifest);
  155. unset($module_upgrade['name'], $module_upgrade['title'], $module_upgrade['ability'], $module_upgrade['description']);
  156. $points = ext_module_bindings();
  157. $bindings = array_elements(array_keys($points), $module_upgrade, false);
  158. foreach ($points as $point_name => $point_info) {
  159. unset($module_upgrade[$point_name]);
  160. if (is_array($bindings[$point_name]) && !empty($bindings[$point_name])) {
  161. foreach ($bindings[$point_name] as $entry) {
  162. $entry['module'] = $manifest['application']['identifie'];
  163. $entry['entry'] = $point_name;
  164. if ($point_name == 'page' && !empty($wxapp_support)) {
  165. $entry['url'] = $entry['do'];
  166. $entry['do'] = '';
  167. }
  168. if ($entry['title'] && $entry['do']) {
  169. $not_delete_do[] = $entry['do'];
  170. $not_delete_title[] = $entry['title'];
  171. $module_binding = table('modules_bindings')->getByEntryDo($module_name, $point_name, $entry['do']);
  172. if (!empty($module_binding)) {
  173. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  174. continue;
  175. }
  176. } elseif ($entry['call']) {
  177. $not_delete_call[] = $entry['call'];
  178. $module_binding = table('modules_bindings')->getByEntryCall($module_name, $point_name, $entry['call']);
  179. if (!empty($module_binding)) {
  180. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  181. continue;
  182. }
  183. }
  184. pdo_insert('modules_bindings', $entry);
  185. }
  186. if (!empty($not_delete_do)) {
  187. 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));
  188. unset($not_delete_do);
  189. }
  190. if (!empty($not_delete_title)) {
  191. 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));
  192. unset($not_delete_title);
  193. }
  194. if (!empty($not_delete_call)) {
  195. 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));
  196. unset($not_delete_call);
  197. }
  198. }
  199. }
  200. if ($packet['schemes']) {
  201. foreach ($packet['schemes'] as $remote) {
  202. $remote['tablename'] = trim(tablename($remote['tablename']), '`');
  203. $local = db_table_schema(pdo(), $remote['tablename']);
  204. $sqls = db_table_fix_sql($local, $remote);
  205. foreach ($sqls as $sql) {
  206. pdo_run($sql);
  207. }
  208. }
  209. }
  210. ext_module_run_script($manifest, 'upgrade');
  211. $module_upgrade['permissions'] = iserializer($module_upgrade['permissions']);
  212. if (!empty($module_info['version']['cloud_setting'])) {
  213. $module_upgrade['settings'] = 2;
  214. } else {
  215. $module_upgrade['settings'] = empty($module_upgrade['settings']) ? 0 : 1;
  216. }
  217. pdo_update('modules', $module_upgrade, array('name' => $module_name));
  218. cache_build_account_modules();
  219. if (!empty($module_upgrade['subscribes'])) {
  220. ext_check_module_subscribe($module_name);
  221. }
  222. cache_delete(cache_system_key('cloud_transtoken'));
  223. cache_build_module_info($module_name);
  224. itoast(empty($_GPC['has_new_support']) ? '模块更新成功!' : '模块安装成功!', url('module/manage-system', array('support' => $module_support_name)), 'success');
  225. }
  226. if ($do =='install') {
  227. if (empty($_W['isfounder'])) {
  228. itoast('您没有安装模块的权限', '', 'error');
  229. }
  230. $module_name = trim($_GPC['module_name']);
  231. $installed_module = module_fetch($module_name);
  232. $manifest = ext_module_manifest($module_name);
  233. if (!empty($manifest)) {
  234. $result = cloud_m_prepare($module_name);
  235. if (is_error($result)) {
  236. itoast($result['message'], referer(), 'error');
  237. }
  238. if (!empty($installed_module)) {
  239. $new_support = module_check_notinstalled_support($installed_module, $manifest['platform']['supports']);
  240. if (empty($new_support)) {
  241. itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  242. } else {
  243. foreach ($new_support as $support => $value) {
  244. if ($value == MODULE_NONSUPPORT_ACCOUNT) {
  245. unset($new_support[$support]);
  246. }
  247. }
  248. pdo_update('modules', $new_support, array('mid' => $installed_module['mid']));
  249. cache_build_account_modules($_W['uniacid'], $_W['uid']);
  250. cache_build_module_info($module_name);
  251. itoast('模块安装成功!', url('module/manage-system', array('support' => $module_support_name)), 'success');
  252. }
  253. }
  254. } else {
  255. $result = cloud_prepare();
  256. if (is_error($result)) {
  257. itoast($result['message'], url('cloud/profile'), 'error');
  258. }
  259. $module_info = cloud_m_info($module_name);
  260. if (!is_error($module_info)) {
  261. $packet = cloud_m_build($module_name);
  262. $manifest = ext_module_manifest_parse($packet['manifest']);
  263. if (empty($manifest)) {
  264. itoast('模块安装配置文件不存在或是格式不正确,请刷新重试!', referer(), 'error');
  265. }
  266. if (!empty($installed_module)) {
  267. $has_new_support = module_check_notinstalled_support($installed_module, $manifest['platform']['supports']);
  268. if (empty($has_new_support)) {
  269. itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  270. }
  271. }
  272. if (empty($_GPC['flag'])) {
  273. if (empty($has_new_support)) {
  274. header('location: ' . url('cloud/process', array('support' => $module_support_name, 'm' => $module_name)));
  275. } else {
  276. header('location: ' . url('cloud/process', array('support' => $module_support_name, 'm' => $module_name, 'is_upgrade' => 1, 'has_new_support' => 1)));
  277. }
  278. exit;
  279. } else {
  280. define('ONLINE_MODULE', true);
  281. }
  282. } else {
  283. itoast($module_info['message'], '', 'error');
  284. }
  285. }
  286. if (!empty($manifest['platform']['main_module'])) {
  287. $plugin_exist = table('modules_plugin')->getPluginExists($manifest['platform']['main_module'], $manifest['application']['identifie']);
  288. if (empty($plugin_exist)) {
  289. itoast('请先更新或安装主模块后再安装插件', url('module/manage-system/installed'), 'error', array(array('title' => '查看主程序', 'url' => url('module/manage-system/module_detail', array('name' => $manifest['platform']['main_module'])))));
  290. }
  291. }
  292. $check_manifest_result = ext_manifest_check($module_name, $manifest);
  293. if (is_error($check_manifest_result)) {
  294. itoast($check_manifest_result['message'], '', 'error');
  295. }
  296. $check_file_result = ext_file_check($module_name, $manifest);
  297. if (is_error($check_file_result)) {
  298. itoast('模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!', '', 'error');
  299. }
  300. $module = ext_module_convert($manifest);
  301. if (!$_W['ispost'] || empty($_GPC['flag'])) {
  302. $module_group = uni_groups();
  303. template('system/module-group');
  304. exit;
  305. }
  306. if (!empty($manifest['platform']['plugin_list'])) {
  307. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  308. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  309. }
  310. }
  311. $post_groups = $_GPC['group'];
  312. $points = ext_module_bindings();
  313. if (!empty($points)) {
  314. $bindings = array_elements(array_keys($points), $module, false);
  315. foreach ($points as $name => $point) {
  316. unset($module[$name]);
  317. if (is_array($bindings[$name]) && !empty($bindings[$name])) {
  318. foreach ($bindings[$name] as $entry) {
  319. $entry['module'] = $manifest['application']['identifie'];
  320. $entry['entry'] = $name;
  321. if ($name == 'page' && !empty($wxapp_support)){
  322. $entry['url'] = $entry['do'];
  323. $entry['do'] = '';
  324. }
  325. table('modules_bindings')->fill($entry)->save();
  326. }
  327. }
  328. }
  329. }
  330. $module['permissions'] = iserializer($module['permissions']);
  331. $module_subscribe_success = true;
  332. if (!empty($module['subscribes'])) {
  333. $subscribes = iunserializer($module['subscribes']);
  334. if (!empty($subscribes)) {
  335. $module_subscribe_success = ext_check_module_subscribe($module['name']);
  336. }
  337. }
  338. if (!empty($module_info['version']['cloud_setting'])) {
  339. $module['settings'] = 2;
  340. }
  341. $module['title_initial'] = get_first_pinyin($module['title']);
  342. if ($packet['schemes']){
  343. foreach ($packet['schemes'] as $remote) {
  344. $remote['tablename'] = trim(tablename($remote['tablename']), '`');
  345. $local = db_table_schema(pdo(), $remote['tablename']);
  346. $sqls = db_table_fix_sql($local, $remote);
  347. foreach ($sqls as $sql) {
  348. pdo_run($sql);
  349. }
  350. }
  351. }
  352. ext_module_run_script($manifest, 'install');
  353. if (pdo_insert('modules', $module)) {
  354. if ($_GPC['flag'] && !empty($post_groups) && $module['name']) {
  355. foreach ($post_groups as $groupid) {
  356. $group_info = pdo_get('uni_group', array('id' => intval($groupid)), array('id', 'name', 'modules'));
  357. if (empty($group_info)) {
  358. continue;
  359. }
  360. $group_info['modules'] = iunserializer($group_info['modules']);
  361. if (!empty($group_info['modules'])) {
  362. $is_continue = false;
  363. foreach ($group_info['modules'] as $modulenames) {
  364. if (in_array($module['name'], $modulenames)) {
  365. $is_continue = true;
  366. break;
  367. }
  368. }
  369. if ($is_continue) {
  370. continue;
  371. }
  372. }
  373. $group_info['modules']['modules'][] = $module['name'];
  374. $group_info['modules']['wxapp'][] = $module['name'];
  375. $group_info['modules']['webapp'][] = $module['name'];
  376. $group_info['modules']['xzapp'][] = $module['name'];
  377. $group_info['modules']['phoneapp'][] = $module['name'];
  378. $group_info['modules'] = iserializer($group_info['modules']);
  379. pdo_update('uni_group', $group_info, array('id' => $groupid));
  380. }
  381. }
  382. cache_build_module_subscribe_type();
  383. cache_build_account_modules($_W['uniacid'], $_W['uid']);
  384. cache_build_module_info($module_name);
  385. cache_build_uni_group();
  386. itoast('模块成功!', url('module/manage-system/install_success', array('support' => $module_support_name)), 'success');
  387. } else {
  388. itoast('模块安装失败, 请联系模块开发者!');
  389. }
  390. }
  391. if ($do == 'change_receive_ban') {
  392. $modulename = trim($_GPC['modulename']);
  393. $module_exist = module_fetch($modulename);
  394. if (empty($module_exist)) {
  395. iajax(1, '模块不存在', '');
  396. }
  397. if (!is_array($_W['setting']['module_receive_ban'])) {
  398. $_W['setting']['module_receive_ban'] = array();
  399. }
  400. if (in_array($modulename, $_W['setting']['module_receive_ban'])) {
  401. unset($_W['setting']['module_receive_ban'][$modulename]);
  402. } else {
  403. $_W['setting']['module_receive_ban'][$modulename] = $modulename;
  404. }
  405. setting_save($_W['setting']['module_receive_ban'], 'module_receive_ban');
  406. cache_build_module_subscribe_type();
  407. cache_build_module_info($module_name);
  408. iajax(0, '');
  409. }
  410. if ($do == 'save_module_info') {
  411. $module_name = trim($_GPC['modulename']);
  412. if (empty($module_name)) {
  413. iajax(1, '数据非法');
  414. }
  415. $module = module_fetch($module_name);
  416. if (empty($module)) {
  417. iajax(1, '数据非法');
  418. }
  419. $module_info_type = key($_GPC['moduleinfo']);
  420. $module_icon_map = array(
  421. 'logo' => array(
  422. 'filename' => 'icon-custom.jpg',
  423. 'url' => trim($_GPC['moduleinfo']['logo'])
  424. ),
  425. 'preview' => array(
  426. 'filename' => 'preview-custom.jpg',
  427. 'url' => trim($_GPC['moduleinfo']['preview'])
  428. ),
  429. );
  430. $module_field = array('title', 'ability', 'description');
  431. if (!isset($module_icon_map[$module_info_type]) && !in_array($module_info_type, $module_field)) {
  432. iajax(1, '数据非法');
  433. }
  434. if (in_array($module_info_type, $module_field)) {
  435. $module_update = array($module_info_type => trim($_GPC['moduleinfo'][$module_info_type]));
  436. if ($module_info_type == 'title') {
  437. $module_update['title_initial'] = get_first_pinyin($_GPC['moduleinfo']['title']);
  438. }
  439. $result = pdo_update('modules', $module_update, array('name' => $module_name));
  440. } else {
  441. $image_destination_url = IA_ROOT . "/addons/" . $module_name . '/' . $module_icon_map[$module_info_type]['filename'];
  442. $result = utility_image_rename($module_icon_map[$module_info_type]['url'], $image_destination_url);
  443. }
  444. cache_build_module_info($module_name);
  445. if (!empty($result)) {
  446. iajax(0, '');
  447. }
  448. iajax(1, '更新失败');
  449. }
  450. if ($do == 'module_detail') {
  451. $_W['page']['title'] = '模块详情';
  452. $module_name = trim($_GPC['name']);
  453. $module_info = module_fetch($module_name);
  454. if (empty($module_info)) {
  455. itoast('模块不存在或是已经被删除', '', 'error');
  456. }
  457. $manifest = ext_module_manifest($module_name);
  458. if (empty($manifest)) {
  459. $current_cloud_module = cloud_m_info($module_name);
  460. if (is_error($current_cloud_module)) {
  461. itoast($current_cloud_module['message']);
  462. }
  463. }
  464. $module_info['cloud_mid'] = !empty($current_cloud_module['id']) ? $current_cloud_module['id'] : '';
  465. foreach ($module_info as $key => $value) {
  466. if ($key != $module_support . '_support' && strexists($key, '_support') && $value == MODULE_SUPPORT_ACCOUNT) {
  467. $module_info['relation'][] = $key;
  468. }
  469. }
  470. if (!empty($module_info['main_module'])) {
  471. $main_module = module_fetch($module_info['main_module']);
  472. }
  473. if (!empty($module_info['plugin_list'])) {
  474. $module_info['plugin_list'] = module_get_plugin_list($module_name);
  475. }
  476. $module_group_list = pdo_getall('uni_group', array('uniacid' => 0, 'uid' => 0));
  477. $module_group = array();
  478. if (!empty($module_group_list)) {
  479. foreach ($module_group_list as $group) {
  480. if (user_is_vice_founder() && $group['owner_uid'] != $_W['uid']) {
  481. continue;
  482. }
  483. $group['modules'] = iunserializer($group['modules']);
  484. if (is_array($group['modules'])) {
  485. foreach ($group['modules'] as $modulenames) {
  486. if (is_array($modulenames) && in_array($module_name, $modulenames)) {
  487. $module_group[] = $group;
  488. break;
  489. }
  490. }
  491. }
  492. }
  493. }
  494. $subscribes_type = ext_module_msg_types();
  495. }
  496. if ($do == 'uninstall') {
  497. if (empty($_W['isfounder'])) {
  498. return error(1, '您没有卸载模块的权限!');
  499. }
  500. $name = trim($_GPC['module_name']);
  501. $module = module_fetch($name, false);
  502. if (empty($module)) {
  503. itoast('应用不存在或是已经卸载!', referer(), 'success');
  504. }
  505. if (!isset($_GPC['confirm'])) {
  506. $message = '';
  507. if ($module['isrulefields']) {
  508. $message .= '是否删除相关规则和统计分析数据<div><a class="btn btn-primary" style="width:80px;" href="' . url('module/manage-system/uninstall', array('module_name' => $name, 'confirm' => 1, 'support' => $module_support_name)) . '">是</a> &nbsp;&nbsp;<a class="btn btn-default" style="width:80px;" href="' . url('module/manage-system/uninstall', array('support' => $module_support_name, 'module_name' => $name, 'confirm' => 0)) . '">否</a></div>';
  509. }
  510. if (!empty($message)) {
  511. message($message, '', 'tips');
  512. }
  513. }
  514. ext_module_uninstall($name, $_GPC['confirm']);
  515. cache_build_account_modules($_W['uniacid'], $_W['uid']);
  516. cache_build_module_subscribe_type();
  517. cache_build_module_info($name);
  518. module_upgrade_info();
  519. itoast('模块已卸载!', url('module/manage-system/recycle', array('support' => $module_support_name, 'type' => MODULE_RECYCLE_INSTALL_DISABLED)), 'success');
  520. }
  521. if ($do == 'recycle_post') {
  522. $name = trim($_GPC['module_name']);
  523. if (empty($name)) {
  524. itoast('应用不存在或是已经被删除', referer(), 'error');
  525. }
  526. $module = module_fetch($name);
  527. $module_recycle = module_recycle_fetch($name);
  528. if (!empty($module)) {
  529. if (empty($module_recycle)) {
  530. $modules_cloud = pdo_get('modules_cloud', array('name' => $name, 'install_status' => array(MODULE_CLOUD_UNINSTALL, MODULE_LOCAL_UNINSTALL)));
  531. if (!empty($modules_cloud)) {
  532. $support = '';
  533. $support_name = array('account' => '公众号', 'wxapp' => '小程序', 'webapp' => 'PC', 'phoneapp' => 'APP', 'welcome' => '系统首页', 'xzapp' => '熊掌号', 'aliapp' => '支付宝小程序');
  534. foreach ($support_name as $name => $value) {
  535. if ($modules_cloud["{$name}_support"] == MODULE_SUPPORT_ACCOUNT) {
  536. $support = $value;
  537. break;
  538. }
  539. }
  540. itoast("该应用有未安装的{$support}支持, 请先安装", referer(), 'error');
  541. }
  542. $msg = '模块已停用!';
  543. table('modules_recycle')->fill(array('name' => $name, 'type' => 1))->save();
  544. } else {
  545. $msg = '模块已恢复!';
  546. table('modules_recycle')->deleteByName($name);
  547. }
  548. cache_write(cache_system_key('user_modules', array('uid' => $_W['uid'])), array());
  549. cache_build_module_info($name);
  550. } else {
  551. if (empty($module_recycle)) {
  552. $msg = '模块已放入回收站!';
  553. table('modules_recycle')->fill(array('name' => $name, 'type' => 2))->save();
  554. } else {
  555. $msg = '模块已恢复!';
  556. table('modules_recycle')->deleteByName($name);
  557. }
  558. }
  559. itoast($msg, referer(), 'success');
  560. }
  561. if ($do == 'recycle') {
  562. $type = intval($_GPC['type']);
  563. $title = safe_gpc_string($_GPC['title']);
  564. $letter = safe_gpc_string($_GPC['letter']);
  565. if ($type == MODULE_RECYCLE_INSTALL_DISABLED) {
  566. $_W['page']['title'] = '已停用模块列表';
  567. } else {
  568. $_W['page']['title'] = '模块回收站';
  569. }
  570. $pageindex = max($_GPC['page'], 1);
  571. $pagesize = 20;
  572. $module_recycle_table = table('modules_recycle');
  573. if ($type == MODULE_RECYCLE_INSTALL_DISABLED) {
  574. $module_recycle_table->searchWithModules();
  575. } else {
  576. $module_recycle_table->searchWithModulesCloud();
  577. }
  578. $module_recycle_table->searchWithPage($pageindex, $pagesize)->where('b.type', $type);
  579. if (!empty($title)) {
  580. $module_recycle_table->where('a.title LIKE', "%{$title}%");
  581. }
  582. if (!empty($letter) && strlen($letter) == 1) {
  583. $module_recycle_table->where('a.title_initial', $letter);
  584. }
  585. $modulelist = $module_recycle_table->getall('name');
  586. if (!empty($modulelist)) {
  587. foreach ($modulelist as $modulename => &$module) {
  588. $module = module_fetch($modulename, false);
  589. if (empty($module)) {
  590. $module = table('modules_cloud')->getByName($modulename);
  591. }
  592. }
  593. unset($module);
  594. $pager = pagination($module_recycle_table->getLastQueryTotal(), $pageindex, $pagesize);
  595. }
  596. $module_uninstall_total = module_uninstall_total($module_support);
  597. }
  598. if ($do == 'installed') {
  599. $_W['page']['title'] = '应用列表';
  600. $module_list = module_installed_list($module_support);
  601. if (!empty($module_list)) {
  602. foreach ($module_list as $key => &$module) {
  603. if (!empty($module['issystem'])) {
  604. unset($module_list[$key]);
  605. }
  606. if (!empty($letter) && strlen($letter) == 1) {
  607. if ($module['title_initial'] != $letter) {
  608. unset($module_list[$key]);
  609. }
  610. }
  611. }
  612. unset($module);
  613. }
  614. $pager = pagination(count($module_list), 1, 15, '', array('ajaxcallback' => true, 'callbackfuncname' => 'loadMore'));
  615. $module_uninstall_total = module_uninstall_total($module_support);
  616. }
  617. if ($do == 'not_installed') {
  618. $_W['page']['title'] = '未安装模块';
  619. $title = safe_gpc_string($_GPC['title']);
  620. $letter = safe_gpc_string($_GPC['letter']);
  621. cache_build_uninstalled_module();
  622. $pageindex = max($_GPC['page'], 1);
  623. $pagesize = 20;
  624. $module_cloud_talbe = table('modules_cloud');
  625. $module_cloud_talbe->searchWithoutRecycle();
  626. $module_cloud_talbe->searchWithPage($pageindex, $pagesize);
  627. if (!empty($title)) {
  628. $module_cloud_talbe->where('a.title LIKE', "%{$title}%");
  629. }
  630. if (!empty($letter) && strlen($letter) == 1) {
  631. $module_cloud_talbe->where('a.title_initial', $letter);
  632. }
  633. $module_cloud_talbe->where('a.install_status', array(MODULE_LOCAL_UNINSTALL, MODULE_CLOUD_UNINSTALL));
  634. $module_cloud_talbe->where("a.{$module_support}_support", MODULE_SUPPORT_ACCOUNT);
  635. $module_cloud_talbe->orderby('a.install_status', 'asc');
  636. $modulelist = $module_cloud_talbe->getall('name');
  637. $pager = pagination($module_cloud_talbe->getLastQueryTotal(), $pageindex, $pagesize);
  638. $module_uninstall_total = module_uninstall_total($module_support);
  639. if ($modulelist) {
  640. foreach ($modulelist as $name => $info) {
  641. $modulelist[$name]['installed_support'] = array();
  642. $module = module_fetch($name);
  643. if (empty($module)) {
  644. continue;
  645. }
  646. if ($module['account_support'] == MODULE_SUPPORT_ACCOUNT && $info['account_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  647. $modulelist[$name]['installed_support'][] = '公众号';
  648. }
  649. if ($module['wxapp_support'] == MODULE_SUPPORT_ACCOUNT && $info['wxapp_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  650. $modulelist[$name]['installed_support'][] = '微信小程序';
  651. }
  652. if ($module['webapp_support'] == MODULE_SUPPORT_ACCOUNT && $info['webapp_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  653. $modulelist[$name]['installed_support'][] = 'PC';
  654. }
  655. if ($module['phoneapp_support'] == MODULE_SUPPORT_ACCOUNT && $info['phoneapp_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  656. $modulelist[$name]['installed_support'][] = 'APP';
  657. }
  658. if ($module['xzapp_support'] == MODULE_SUPPORT_ACCOUNT && $info['xzapp_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  659. $modulelist[$name]['installed_support'][] = '熊账号';
  660. }
  661. if ($module['aliapp_support'] == MODULE_SUPPORT_ACCOUNT && $info['aliapp_support'] == MODULE_NONSUPPORT_ACCOUNT) {
  662. $modulelist[$name]['installed_support'][] = '支付宝小程序';
  663. }
  664. }
  665. }
  666. }
  667. template('module/manage-system');