manage-system.ctrl.php 29 KB

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