人人商城

system.ctrl.php 28KB

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