manage-system.ctrl.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. load()->model('store');
  17. $dos = array('subscribe', 'check_subscribe', 'check_upgrade', 'get_local_upgrade_info', 'get_upgrade_info', 'upgrade',
  18. 'install', 'installed', 'not_installed', 'uninstall', 'save_module_info', 'module_detail',
  19. 'change_receive_ban', 'install_success', 'set_site_welcome_module',
  20. 'founder_update_modules', 'recycle', 'recycle_post', 'init_modules_logo'
  21. );
  22. $do = in_array($do, $dos) ? $do : 'installed';
  23. if (user_is_vice_founder() && !empty($_GPC['system_welcome'])){
  24. itoast('无权限操作!');
  25. }
  26. if ($do == 'set_site_welcome_module') {
  27. if (!$_W['isfounder']) {
  28. iajax(1, '非法操作');
  29. }
  30. if (!empty($_GPC['name'])) {
  31. $site = WeUtility::createModuleSystemWelcome($_GPC['name']);
  32. if (!method_exists($site, 'systemWelcomeDisplay')) {
  33. iajax(1, '应用未实现系统首页功能!');
  34. }
  35. }
  36. setting_save(trim($_GPC['name']), 'site_welcome_module');
  37. iajax(0);
  38. }
  39. $permission_check = array(
  40. 'see_module_manage_system_install' => permission_check_account_user('see_module_manage_system_install') ? 1 : 0,
  41. 'see_module_manage_system_shopinfo' => permission_check_account_user('see_module_manage_system_shopinfo') ? 1 : 0,
  42. 'see_module_manage_system_stop' => permission_check_account_user('see_module_manage_system_stop') ? 1 : 0,
  43. );
  44. if ($do == 'subscribe') {
  45. $module_uninstall_total = module_uninstall_total($module_support);
  46. $module_list = user_modules($_W['uid']);
  47. $subscribe_type = ext_module_msg_types();
  48. $subscribe_module = array();
  49. $receive_ban = $_W['setting']['module_receive_ban'];
  50. if (is_array($module_list) && !empty($module_list)) {
  51. foreach ($module_list as $module) {
  52. if (!empty($module['subscribes']) && is_array($module['subscribes'])) {
  53. $subscribe_module[$module['name']]['subscribe'] = $module['subscribes'];
  54. $subscribe_module[$module['name']]['title'] = $module['title'];
  55. $subscribe_module[$module['name']]['name'] = $module['name'];
  56. $subscribe_module[$module['name']]['subscribe_success'] = 2;
  57. $subscribe_module[$module['name']]['receive_ban'] = in_array($module['name'], $receive_ban) ? 1 : 0;
  58. }
  59. }
  60. }
  61. }
  62. if ($do == 'check_subscribe') {
  63. $module = module_fetch($_GPC['module_name']);
  64. if (empty($module)) {
  65. iajax(1);
  66. }
  67. $obj = WeUtility::createModuleReceiver($module['name']);
  68. if (empty($obj)) {
  69. iajax(1);
  70. }
  71. $obj->uniacid = $_W['uniacid'];
  72. $obj->acid = $_W['acid'];
  73. $obj->message = array(
  74. 'event' => 'subscribe'
  75. );
  76. if(method_exists($obj, 'receive')) {
  77. @$obj->receive();
  78. iajax(0);
  79. } else {
  80. iajax(1);
  81. }
  82. }
  83. if ($do == 'get_local_upgrade_info') {
  84. $modulename = safe_gpc_string($_GPC['name']);
  85. $module = module_fetch($modulename);
  86. if (empty($module)) {
  87. iajax(1, '模块不存在!');
  88. }
  89. $manifest = ext_module_manifest($modulename);
  90. if (!empty($manifest) && version_compare($manifest['application']['version'], $module['version'], '>')) {
  91. $local_result = array(
  92. 'name' => $modulename,
  93. 'upgrade' => true,
  94. 'site_branch' => array(),
  95. 'branches' => array(),
  96. 'new_branch' => false,
  97. 'from' => 'local',
  98. 'best_version' => $manifest['application']['version'],
  99. );
  100. }
  101. iajax(0, $local_result);
  102. }
  103. if ($do == 'get_upgrade_info') {
  104. $modulename = safe_gpc_string($_GPC['name']);
  105. $module = module_fetch($modulename);
  106. if (empty($module)) {
  107. iajax(1, '模块不存在!');
  108. }
  109. $manifest_cloud = cloud_m_upgradeinfo($modulename);
  110. if (is_error($manifest_cloud)) {
  111. iajax(1, $manifest_cloud['message']);
  112. }
  113. $result = array(
  114. 'name' => $modulename,
  115. 'upgrade' => $manifest_cloud['upgrade'],
  116. 'site_branch' => $manifest_cloud['site_branch'],
  117. 'new_branch' => $manifest_cloud['new_branch'],
  118. 'branches' => !empty($manifest_cloud['branches']) ? $manifest_cloud['branches'] : '',
  119. 'from' => 'cloud',
  120. 'id' => $manifest_cloud['id'],
  121. );
  122. iajax(0, $result);
  123. }
  124. if ($do == 'check_upgrade') {
  125. $module_upgrade = module_upgrade_info();
  126. if (is_error($module_upgrade)) {
  127. iajax(-1, $module_upgrade['message']);
  128. }
  129. cache_build_uninstalled_module();
  130. iajax(0, $module_upgrade);
  131. }
  132. if ($do == 'upgrade') {
  133. $module_name = safe_gpc_string(trim($_GPC['module_name']));
  134. $has_new_support = safe_gpc_boolean($_GPC['has_new_support']); $module = table('modules')->getByName($module_name);
  135. if (empty($module)) {
  136. itoast('模块已经被卸载或是不存在!', '', 'error');
  137. }
  138. $manifest = ext_module_manifest($module_name);
  139. if (empty($manifest)) {
  140. $cloud_prepare = cloud_prepare();
  141. if (is_error($cloud_prepare)) {
  142. iajax(1, $cloud_prepare['message']);
  143. }
  144. $module_info = cloud_m_upgradeinfo($module_name);
  145. if (is_error($module_info)) {
  146. iajax(1, $module_info);
  147. }
  148. if (!empty($_GPC['flag'])) {
  149. define('ONLINE_MODULE', true);
  150. $packet = cloud_m_build($module_name);
  151. if (is_error($packet)) {
  152. $extend_button = array();
  153. if ($packet['errno'] == -3) {
  154. $extend_button[] = array('url' => "https://bbs.5g-yun.com/module-{$packet['cloud_id']}.html", 'title' => '去续费', 'target' => '_blank');
  155. }
  156. message($packet['message'], url('module/manage-system', array('support' => $module_support_name)), 'error', true, $extend_button);
  157. }
  158. $manifest = ext_module_manifest_parse($packet['manifest']);
  159. }
  160. }
  161. if (empty($manifest)) {
  162. itoast('模块安装配置文件不存在或是格式不正确!', '', 'error');
  163. }
  164. /*if (empty($manifest['uninstall']) || $manifest['uninstall'] == 'uninstall.php' && !file_exists(IA_ROOT . '/addons/' . $module_name . '/uninstall.php')) {
  165. itoast('模块卸载脚本未完善,会导致后期不用该模块时,产生大量冗余数据。<br>请第一时间<span class="color-red"> 联系开发者完善 </span>并解决!', url('module/manage-system'), 'error');
  166. }*/
  167. $check_manifest_result = ext_manifest_check($module_name, $manifest);
  168. if (is_error($check_manifest_result)) {
  169. itoast($check_manifest_result['message'], '', 'error');
  170. }
  171. $check_file_result = ext_file_check($module_name, $manifest);
  172. if (is_error($check_file_result)) {
  173. itoast($check_file_result['message'], '', 'error');
  174. }
  175. if ($has_new_support && empty($_GPC['upgrade_flag'])) {
  176. $module_group = uni_groups();
  177. template('system/module-group');
  178. exit;
  179. }
  180. if (!empty($manifest['platform']['plugin_list'])) {
  181. pdo_delete('modules_plugin', array('main_module' => $manifest['application']['identifie']));
  182. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  183. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  184. }
  185. }
  186. $module_upgrade = ext_module_convert($manifest);
  187. unset($module_upgrade['name'], $module_upgrade['title'], $module_upgrade['ability'], $module_upgrade['description']);
  188. $points = ext_module_bindings();
  189. $bindings = array_elements(array_keys($points), $module_upgrade, false);
  190. foreach ($points as $point_name => $point_info) {
  191. unset($module_upgrade[$point_name]);
  192. if (is_array($bindings[$point_name]) && !empty($bindings[$point_name])) {
  193. foreach ($bindings[$point_name] as $entry) {
  194. $entry['module'] = $manifest['application']['identifie'];
  195. $entry['entry'] = $point_name;
  196. if ($point_name == 'page' && !empty($wxapp_support)) {
  197. $entry['url'] = $entry['do'];
  198. $entry['do'] = '';
  199. }
  200. if ($entry['title'] && $entry['do']) {
  201. $not_delete_do[] = $entry['do'];
  202. $module_binding = table('modules_bindings')->getByEntryDo($module_name, $point_name, $entry['do']);
  203. if (!empty($module_binding)) {
  204. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  205. continue;
  206. }
  207. } elseif ($entry['call']) {
  208. $not_delete_call[] = $entry['call'];
  209. $module_binding = table('modules_bindings')->getByEntryCall($module_name, $point_name, $entry['call']);
  210. if (!empty($module_binding)) {
  211. pdo_update('modules_bindings', $entry, array('eid' => $module_binding['eid']));
  212. continue;
  213. }
  214. }
  215. pdo_insert('modules_bindings', $entry);
  216. }
  217. $modules_bindings_table = table('modules_bindings');
  218. $modules_bindings_table
  219. ->searchWithModuleEntry($manifest['application']['identifie'], $point_name)
  220. ->where('call', '')
  221. ->where('do !=', empty($not_delete_do) ? '' : $not_delete_do)
  222. ->delete();
  223. $modules_bindings_table
  224. ->searchWithModuleEntry($manifest['application']['identifie'], $point_name)
  225. ->where('do', '')
  226. ->where('title', '')
  227. ->where('call !=', empty($not_delete_call) ? '' : $not_delete_call)
  228. ->delete();
  229. unset($not_delete_do, $not_delete_call);
  230. } else {
  231. table('modules_bindings')->searchWithModuleEntry($manifest['application']['identifie'], $point_name)->delete();
  232. }
  233. }
  234. if ($packet['schemes']) {
  235. foreach ($packet['schemes'] as $remote) {
  236. $remote['tablename'] = trim(tablename($remote['tablename']), '`');
  237. $local = db_table_schema(pdo(), $remote['tablename']);
  238. $sqls = db_table_fix_sql($local, $remote);
  239. foreach ($sqls as $sql) {
  240. pdo_run($sql);
  241. }
  242. }
  243. }
  244. ext_module_run_script($manifest, 'upgrade');
  245. $module_upgrade['permissions'] = iserializer($module_upgrade['permissions']);
  246. if (!empty($module_info['version']['cloud_setting'])) {
  247. $module_upgrade['settings'] = 2;
  248. } else {
  249. $module_upgrade['settings'] = empty($module_upgrade['settings']) ? 0 : 1;
  250. }
  251. if (!empty($_GPC['support'])) {
  252. $support = explode(',', $_GPC['support']);
  253. }
  254. if ($has_new_support) {
  255. $module_support_type = module_support_type();
  256. foreach ($module_support_type as $support_name => $info) {
  257. if (!in_array($support_name, $support)) {
  258. $module_upgrade[$support_name] = $module[$support_name];
  259. }
  260. }
  261. }
  262. pdo_update('modules', $module_upgrade, array('name' => $module_name));
  263. $post_groups = $_GPC['group'];
  264. if ($_GPC['upgrade_flag'] && !empty($post_groups)) {
  265. $module_upgrade['name'] = $module_name;
  266. foreach ($post_groups as $groupid) {
  267. foreach ($support as $val) {
  268. module_add_to_uni_group($module_upgrade, $groupid, $val);
  269. }
  270. }
  271. }
  272. cache_build_account_modules();
  273. if (!empty($module_upgrade['subscribes'])) {
  274. ext_check_module_subscribe($module_name);
  275. }
  276. cache_delete(cache_system_key('cloud_transtoken'));
  277. cache_build_module_info($module_name);
  278. cache_build_uni_group();
  279. if ($has_new_support) {
  280. itoast('模块安装成功!', url('module/manage-system/installed'), 'success');
  281. } else {
  282. itoast('模块更新成功!', url('module/manage-system/installed'), 'success');
  283. }
  284. }
  285. if ($do =='install') {
  286. if (empty($_W['isfounder'])) {
  287. itoast('您没有安装模块的权限', '', 'error');
  288. }
  289. $module_name = safe_gpc_string(trim($_GPC['module_name']));
  290. $installed_module = table('modules')->getByName($module_name);
  291. if (!empty($_GPC['install_module_support'])){
  292. $module_support_name = $_GPC['install_module_support'];
  293. }
  294. $manifest = ext_module_manifest($module_name);
  295. $module_is_cloud = true;
  296. if (!empty($manifest)) {
  297. $module_is_cloud = false;
  298. $module['from'] = 'local';//qwj
  299. $result = cloud_m_prepare($module_name);
  300. if (is_error($result)) {
  301. itoast($result['message'], referer(), 'error');
  302. }
  303. if (!empty($installed_module)) {
  304. $has_new_support = module_check_notinstalled_support($installed_module, $manifest['platform']['supports']);
  305. if (empty($has_new_support)) {
  306. itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  307. } else {
  308. header('location: ' . url('module/manage-system/upgrade', array('support' => $module_support_name, 'module_name' => $module_name, 'has_new_support' => 1)));
  309. exit;
  310. }
  311. }
  312. } else {
  313. $result = cloud_prepare();
  314. if (is_error($result)) {
  315. itoast($result['message'], url('cloud/profile'), 'error');
  316. }
  317. $module_info = cloud_m_info($module_name);
  318. if (is_error($module_info)) {
  319. itoast($module_info['message'], '', 'error');
  320. }
  321. $packet = cloud_m_build($module_name);
  322. if (is_error($packet)) {
  323. $extend_button = array();
  324. if ($packet['errno'] == -3) {
  325. $extend_button[] = array('url' => "https://bbs.5g-yun.com/module-{$packet['cloud_id']}.html", 'title' => '去续费', 'target' => '_blank');
  326. }
  327. message($packet['message'], '', 'error', true, $extend_button);
  328. }
  329. $manifest = ext_module_manifest_parse($packet['manifest']);
  330. if (empty($manifest)) {
  331. itoast('模块安装配置文件不存在或是格式不正确,请刷新重试!', referer(), 'error');
  332. }
  333. if (!empty($installed_module)) {
  334. $has_new_support = module_check_notinstalled_support($installed_module, $manifest['platform']['supports']);
  335. if (empty($has_new_support)) {
  336. itoast('模块已经安装或是唯一标识已存在!', '', 'error');
  337. } else {
  338. header('location: ' . url('cloud/process', array('support' => $module_support_name, 'm' => $module_name, 'is_upgrade' => 1, 'has_new_support' => 1)));
  339. exit;
  340. }
  341. }
  342. if (empty($_GPC['flag'])) {
  343. header('location: ' . url('cloud/process', array('support' => $module_support_name, 'm' => $module_name)));
  344. exit;
  345. } else {
  346. define('ONLINE_MODULE', true);
  347. }
  348. }
  349. /*if (empty($manifest['uninstall'])) {
  350. itoast('模块卸载脚本未完善,会导致后期不用该模块时,产生大量冗余数据。<br>请第一时间<span class="color-red"> 联系开发者完善 </span>并解决!', referer(), 'error');
  351. }*/
  352. if (!empty($manifest['platform']['main_module'])) {
  353. $main_module_fetch = module_fetch($manifest['platform']['main_module']);
  354. if (empty($main_module_fetch)) {
  355. itoast('请先安装主模块后再安装插件', url('module/manage-system/installed'), 'error', array(array('title' => '查看主程序', 'url' => url('module/manage-system/module_detail', array('name' => $manifest['platform']['main_module'])))));
  356. }
  357. $plugin_exist = table('modules_plugin')->getPluginExists($manifest['platform']['main_module'], $manifest['application']['identifie']);
  358. if (empty($plugin_exist)) {
  359. pdo_insert('modules_plugin', array('main_module' => $manifest['platform']['main_module'], 'name' => $manifest['application']['identifie']));
  360. }
  361. }
  362. $check_manifest_result = ext_manifest_check($module_name, $manifest);
  363. if (is_error($check_manifest_result)) {
  364. itoast($check_manifest_result['message'], '', 'error');
  365. }
  366. $check_file_result = ext_file_check($module_name, $manifest);
  367. if (is_error($check_file_result)) {
  368. itoast('模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!', '', 'error');
  369. }
  370. $module = ext_module_convert($manifest);
  371. if (file_exists (IA_ROOT . '/addons/' . $module['name'] . '/icon-custom.jpg')) {
  372. $module['logo'] = 'addons/' . $module['name'] . '/icon-custom.jpg';
  373. } else {
  374. $module['logo'] = 'addons/' . $module['name'] . '/icon.jpg';
  375. }
  376. if (!$_W['ispost'] || empty($_GPC['flag'])) {
  377. $module_group = uni_groups();
  378. template('system/module-group');
  379. exit;
  380. }
  381. if (!empty($manifest['platform']['plugin_list'])) {
  382. foreach ($manifest['platform']['plugin_list'] as $plugin) {
  383. pdo_insert('modules_plugin', array('main_module' => $manifest['application']['identifie'], 'name' => $plugin));
  384. }
  385. }
  386. $post_groups = $_GPC['group'];
  387. $points = ext_module_bindings();
  388. if (!empty($points)) {
  389. $bindings = array_elements(array_keys($points), $module, false);
  390. table('modules_bindings')->deleteByName($manifest['application']['identifie']);
  391. foreach ($points as $name => $point) {
  392. unset($module[$name]);
  393. if (is_array($bindings[$name]) && !empty($bindings[$name])) {
  394. foreach ($bindings[$name] as $entry) {
  395. $entry['module'] = $manifest['application']['identifie'];
  396. $entry['entry'] = $name;
  397. if ($name == 'page' && !empty($wxapp_support)){
  398. $entry['url'] = $entry['do'];
  399. $entry['do'] = '';
  400. }
  401. table('modules_bindings')->fill($entry)->save();
  402. }
  403. }
  404. }
  405. }
  406. $module['permissions'] = iserializer($module['permissions']);
  407. $module_subscribe_success = true;
  408. if (!empty($module['subscribes'])) {
  409. $subscribes = iunserializer($module['subscribes']);
  410. if (!empty($subscribes)) {
  411. $module_subscribe_success = ext_check_module_subscribe($module['name']);
  412. }
  413. }
  414. if (!empty($module_info['version']['cloud_setting'])) {
  415. $module['settings'] = 2;
  416. }
  417. $module['title_initial'] = get_first_pinyin($module['title']);
  418. if ($packet['schemes']){
  419. foreach ($packet['schemes'] as $remote) {
  420. $remote['tablename'] = trim(tablename($remote['tablename']), '`');
  421. $local = db_table_schema(pdo(), $remote['tablename']);
  422. $sqls = db_table_fix_sql($local, $remote);
  423. foreach ($sqls as $sql) {
  424. pdo_run($sql);
  425. }
  426. }
  427. }
  428. ext_module_run_script($manifest, 'install');
  429. $module_support_name_arr = explode(',', $module_support_name);
  430. $all_support = module_support_type();
  431. foreach ($all_support as $support => $value) {
  432. if (!in_array($support, $module_support_name_arr)) {
  433. $module[$support] = $value['not_support'];
  434. }
  435. }
  436. $module_store_goods_info = pdo_get('site_store_goods', array('module' => $module_name));
  437. if (!empty($module_store_goods_info) && $module_store_goods_info['is_wish'] == 1) {
  438. $module['title'] = $module_store_goods_info['title'];
  439. $module['title_initial'] = get_first_pinyin($module_store_goods_info['title']);
  440. $module['logo'] = $module_store_goods_info['logo'];
  441. }
  442. //by RubySn0w 如果这里改成 if (!$module_is_cloud) {$module['from'] = 'local';},相应的module表from项默认值改成'cloud'。
  443. if ($module_is_cloud) {
  444. $module['from'] = 'cloud';
  445. }
  446. if (pdo_insert('modules', $module)) {
  447. if ($_GPC['flag'] && !empty($post_groups) && $module['name']) {
  448. foreach ($post_groups as $groupid) {
  449. foreach ($module_support_name_arr as $support_name) {
  450. module_add_to_uni_group($module, $groupid, $support_name);
  451. }
  452. }
  453. }
  454. $store_goods_id = pdo_getcolumn('site_store_goods', array('module' => $module['name'], 'is_wish' => 1), 'id');
  455. if (!empty($store_goods_id)) {
  456. $store_goods_orders = pdo_getall('site_store_order', array('goodsid' => $store_goods_id));
  457. }
  458. if (!empty($store_goods_orders)) {
  459. foreach ($store_goods_orders as $store_order_info) {
  460. cache_build_account_modules($store_order_info['uniacid']);
  461. }
  462. }
  463. cache_build_module_subscribe_type();
  464. cache_build_module_info($module_name);
  465. cache_build_uni_group();
  466. cache_delete(cache_system_key('user_modules', array('uid' => $_W['uid'])));
  467. if ($module_support_name == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  468. itoast('模块安装成功!', url('module/manage-system/install_success', array('support' => $module_support_name)), 'success');
  469. }
  470. itoast('模块安装成功!', url('module/manage-system/install_success'), 'success');
  471. } else {
  472. itoast('模块安装失败, 请联系模块开发者!');
  473. }
  474. }
  475. if ($do == 'change_receive_ban') {
  476. $modulename = trim($_GPC['modulename']);
  477. $module_exist = module_fetch($modulename);
  478. if (empty($module_exist)) {
  479. iajax(1, '模块不存在', '');
  480. }
  481. if (!is_array($_W['setting']['module_receive_ban'])) {
  482. $_W['setting']['module_receive_ban'] = array();
  483. }
  484. if (in_array($modulename, $_W['setting']['module_receive_ban'])) {
  485. unset($_W['setting']['module_receive_ban'][$modulename]);
  486. } else {
  487. $_W['setting']['module_receive_ban'][$modulename] = $modulename;
  488. }
  489. setting_save($_W['setting']['module_receive_ban'], 'module_receive_ban');
  490. cache_build_module_subscribe_type();
  491. cache_build_module_info($modulename);
  492. iajax(0, '');
  493. }
  494. if ($do == 'save_module_info') {
  495. $module_name = trim($_GPC['modulename']);
  496. if (empty($module_name)) {
  497. iajax(1, '数据非法');
  498. }
  499. $module = module_fetch($module_name);
  500. if (empty($module)) {
  501. iajax(1, '数据非法');
  502. }
  503. $module_info_type = key($_GPC['moduleinfo']);
  504. $module_icon_map = array(
  505. 'logo' => array(
  506. 'filename' => 'icon-custom.jpg',
  507. 'url' => trim($_GPC['moduleinfo']['logo'])
  508. ),
  509. 'preview' => array(
  510. 'filename' => 'preview-custom.jpg',
  511. 'url' => trim($_GPC['moduleinfo']['preview'])
  512. ),
  513. );
  514. $module_field = array('title', 'ability', 'description', 'logo');
  515. if (!isset($module_icon_map[$module_info_type]) && !in_array($module_info_type, $module_field)) {
  516. iajax(1, '数据非法');
  517. }
  518. if (in_array($module_info_type, $module_field)) {
  519. $module_update = array($module_info_type => trim($_GPC['moduleinfo'][$module_info_type]));
  520. if ($module_info_type == 'title') {
  521. $module_update['title_initial'] = get_first_pinyin($_GPC['moduleinfo']['title']);
  522. }
  523. if ($module_info_type == 'logo') {
  524. $module_update['logo'] = trim($_GPC['moduleinfo']['logo']);
  525. }
  526. $result = pdo_update('modules', $module_update, array('name' => $module_name));
  527. }
  528. if (in_array($module_info_type, array('logo', 'preview'))) {
  529. $image_destination_url = IA_ROOT . "/addons/" . $module_name . '/' . $module_icon_map[$module_info_type]['filename'];
  530. $result = utility_image_rename($module_icon_map[$module_info_type]['url'], $image_destination_url);
  531. }
  532. cache_build_module_info($module_name);
  533. if (!empty($result)) {
  534. iajax(0, '');
  535. }
  536. iajax(1, '更新失败');
  537. }
  538. if ($do == 'module_detail') {
  539. $module_name = trim($_GPC['name']);
  540. $module_info = module_fetch($module_name);
  541. if (empty($module_info)) {
  542. itoast('模块不存在或是已经被删除', '', 'error');
  543. }
  544. $manifest = ext_module_manifest($module_name);
  545. if (empty($manifest)) {
  546. $current_cloud_module = cloud_m_info($module_name);
  547. $module_info['cloud_mid'] = !empty($current_cloud_module['id']) ? $current_cloud_module['id'] : '';
  548. }
  549. foreach ($module_info as $key => $value) {
  550. if ($key != $module_support . '_support' && strexists($key, '_support') && $value == MODULE_SUPPORT_ACCOUNT) {
  551. $module_info['relation'][] = $key;
  552. }
  553. }
  554. if (!empty($module_info['main_module'])) {
  555. $main_module = module_fetch($module_info['main_module']);
  556. }
  557. if (!empty($module_info['plugin_list'])) {
  558. $module_info['plugin_list'] = module_get_plugin_list($module_name);
  559. }
  560. $module_group_list = pdo_getall('uni_group', array('uniacid' => 0, 'uid' => 0));
  561. $module_group = array();
  562. if (!empty($module_group_list)) {
  563. foreach ($module_group_list as $group) {
  564. if (user_is_vice_founder() && $group['owner_uid'] != $_W['uid']) {
  565. continue;
  566. }
  567. $group['modules'] = iunserializer($group['modules']);
  568. if (is_array($group['modules'])) {
  569. foreach ($group['modules'] as $modulenames) {
  570. if (is_array($modulenames) && in_array($module_name, $modulenames)) {
  571. $module_group[] = $group;
  572. break;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. $subscribes_type = ext_module_msg_types();
  579. }
  580. if ($do == 'uninstall') {
  581. if (empty($_W['isfounder'])) {
  582. return error(1, '您没有卸载模块的权限!');
  583. }
  584. $name = safe_gpc_string(trim($_GPC['module_name']));
  585. $module = module_fetch($name, false);
  586. if (empty($module) || $module[$module_support_name] != MODULE_SUPPORT_ACCOUNT) {
  587. itoast('应用不存在或是已经卸载!', referer(), 'success');
  588. }
  589. $module[$module_support_name] = MODULE_NONSUPPORT_ACCOUNT;
  590. $uninstall_all = true;
  591. foreach (module_support_type() as $support => $value) {
  592. if ($module[$support] == MODULE_SUPPORT_ACCOUNT) {
  593. $uninstall_all = false;
  594. break;
  595. }
  596. }
  597. if ($uninstall_all) {
  598. if (!isset($_GPC['confirm'])) {
  599. $message = '';
  600. if ($module['isrulefields']) {
  601. $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>';
  602. }
  603. if (!empty($message)) {
  604. message($message, '', 'tips');
  605. }
  606. }
  607. ext_module_uninstall($name, $_GPC['confirm']);
  608. cache_build_module_subscribe_type();
  609. } else {
  610. table('modules')->where('mid', $module['mid'])->fill($module_support_name, MODULE_NONSUPPORT_ACCOUNT)->save();
  611. module_cancel_recycle($name, MODULE_RECYCLE_INSTALL_DISABLED, $module_support_name);
  612. }
  613. cache_build_account_modules($_W['uniacid'], $_W['uid']);
  614. cache_build_module_info($name);
  615. module_upgrade_info();
  616. if ($module_support_name == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  617. itoast('模块已卸载!', url('module/manage-system/recycle', array('type' => MODULE_RECYCLE_INSTALL_DISABLED, 'support' => $module_support_name)), 'success');
  618. }
  619. itoast('模块已卸载!', url('module/manage-system/recycle', array('type' => MODULE_RECYCLE_INSTALL_DISABLED)), 'success');
  620. }
  621. if ($do == 'recycle_post') {
  622. $name = safe_gpc_string(trim($_GPC['module_name']));
  623. if (empty($name)) {
  624. itoast('应用不存在或是已经被删除', referer(), 'error');
  625. }
  626. if (!empty($_GPC['supports'])) {
  627. $supports = safe_gpc_array($_GPC['supports']);
  628. } else {
  629. $supports = array(safe_gpc_string($_GPC['support']));
  630. }
  631. $module = table('modules')->getByName($name);
  632. $recycle_table = table('modules_recycle');
  633. foreach ($supports as $support) {
  634. if (!in_array($support, array_keys(module_support_type()))) {
  635. continue;
  636. }
  637. $recycle_table->searchWithSupport($support);
  638. if (!empty($module[$support]) && $module[$support] == 2) {
  639. $module_recycle = $recycle_table->searchWithNameType($name, 1)->get();
  640. if (empty($module_recycle)) {
  641. $msg = '模块已停用!';
  642. module_recycle($name, MODULE_RECYCLE_INSTALL_DISABLED, $support);
  643. } else {
  644. $msg = '模块已恢复!';
  645. module_cancel_recycle($name, MODULE_RECYCLE_INSTALL_DISABLED, $support);
  646. }
  647. cache_write(cache_system_key('user_modules', array('uid' => $_W['uid'])), array());
  648. cache_build_module_info($name);
  649. } else {
  650. $module_recycle = $recycle_table->searchWithNameType($name, 2)->get();
  651. if (empty($module_recycle)) {
  652. $msg = '模块已放入回收站!';
  653. module_recycle($name, MODULE_RECYCLE_UNINSTALL_IGNORE, $support);
  654. } else {
  655. $msg = '模块已恢复!';
  656. module_cancel_recycle($name, MODULE_RECYCLE_UNINSTALL_IGNORE, $support);
  657. }
  658. }
  659. }
  660. itoast($msg, referer(), 'success');
  661. }
  662. if ($do == 'recycle') {
  663. $type = intval($_GPC['type']);
  664. $support = safe_gpc_string($_GPC['support']);
  665. $support = empty($support) ? 'all' : $support;
  666. $title = safe_gpc_string($_GPC['title']);
  667. $letter = safe_gpc_string($_GPC['letter']);
  668. $pageindex = max($_GPC['page'], 1);
  669. $pagesize = 15;
  670. $module_recycle_table = table('modules_recycle');
  671. $fields = $support == 'all' ? 'a.title, a.title_initial, a.logo, a.version, b.*' : 'a.*, b.type';
  672. if ($type == MODULE_RECYCLE_INSTALL_DISABLED) {
  673. $module_recycle_table->searchWithModules($fields);
  674. } else {
  675. $fields .= $support == 'all' ? ', a.cloud_id' : '';
  676. $module_recycle_table->searchWithModulesCloud($fields);
  677. }
  678. $module_recycle_table->where('b.type', $type);
  679. if ($support != 'all') {
  680. $module_recycle_table->where("b.{$support}", 1);
  681. }
  682. if (!empty($title)) {
  683. $module_recycle_table->where('a.title LIKE', "%{$title}%");
  684. }
  685. if (!empty($letter) && strlen($letter) == 1) {
  686. $module_recycle_table->where('a.title_initial', $letter);
  687. }
  688. $modulelist = $module_recycle_table->getall();
  689. if (!empty($modulelist)) {
  690. $module_support_type = module_support_type();
  691. $modulelist_recycle = array();
  692. foreach ($modulelist as $modulename => &$module) {
  693. $module_recycle_info = $module;
  694. $module = module_fetch($module['name'], false);
  695. if (empty($module)) {
  696. $module = table('modules_cloud')->getByName($module_recycle_info['name']);
  697. }
  698. $module['cloud_id'] = $module_recycle_info['cloud_id'];
  699. foreach ($module_support_type as $type_key => $type_val) {
  700. if ($support == 'all') {
  701. if ($module_recycle_info[$type_key] == 1 && $type_key != MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  702. $module['support'] = $module_recycle_info['support'] = $type_key;
  703. $module['support_name'] = $module_recycle_info['support_name'] = $type_val['type_name'];
  704. $module_recycle_info['logo'] = $module['logo'];
  705. $modulelist_recycle[$module_recycle_info['name'] . '_' . $type_key] = $module_recycle_info;
  706. }
  707. } else {
  708. $module['support'] = $support;
  709. $module['support_name'] = $module_support_type[$support]['type_name'];
  710. }
  711. }
  712. }
  713. unset($module);
  714. }
  715. if ($support == 'all') {
  716. $modulelist = $modulelist_recycle;
  717. }
  718. $total = count($modulelist);
  719. $pager = pagination($total, $pageindex, $pagesize, '', array('ajaxcallback' => true, 'callbackfuncname' => 'loadMore'));
  720. $module_uninstall_total = module_uninstall_total($module_support);
  721. }
  722. if ($do == 'installed') {
  723. $module_list = module_installed_list($module_support);
  724. $module_support_types = module_support_type();
  725. if (!empty($module_list)) {
  726. foreach ($module_list as $key => &$module) {
  727. if (!empty($module['issystem'])) {
  728. unset($module_list[$key]);
  729. }
  730. if ($module_support != 'all') {
  731. $module['support_name'] = $module_support_types[$module_support_name]['type_name'];
  732. }
  733. }
  734. unset($module);
  735. }
  736. if ($module_support == 'all') {
  737. $module_list_support = array();
  738. if (!empty($module_list)) {
  739. foreach ($module_list as $key => &$module) {
  740. foreach ($module_support_types as $module_support_type => $module_support_val) {
  741. if ($module_support_type == MODULE_SUPPORT_SYSTEMWELCOME_NAME) {
  742. continue;
  743. }
  744. if ($module[$module_support_type] == $module_support_val['support']) {
  745. $module['support'] = $module_support_type;
  746. $module['support_name'] = $module_support_val['type_name'];
  747. $module_list_support[$module['name'] . '_' . $module_support_type] = $module;
  748. }
  749. }
  750. }
  751. unset($module);
  752. }
  753. $module_list = $module_list_support;
  754. }
  755. $pager = pagination(count($module_list), 1, 15, '', array('ajaxcallback' => true, 'callbackfuncname' => 'loadMore'));
  756. $module_uninstall_total = module_uninstall_total($module_support);
  757. }
  758. if ($do == 'not_installed') {
  759. $title = safe_gpc_string($_GPC['title']);
  760. $letter = safe_gpc_string($_GPC['letter']);
  761. $module_support_types = module_support_type();
  762. cache_build_uninstalled_module();
  763. $module_cloud_table = table('modules_cloud');
  764. if (!empty($title)) {
  765. $module_cloud_table->where('title LIKE', "%{$title}%");
  766. }
  767. if (!empty($letter) && strlen($letter) == 1) {
  768. $module_cloud_table->where('title_initial', $letter);
  769. }
  770. if ($module_support != 'all') {
  771. $module_cloud_table->where($module_support . '_support', 2);
  772. }
  773. $module_cloud_table->where('install_status', array(MODULE_LOCAL_UNINSTALL, MODULE_CLOUD_UNINSTALL));
  774. $module_cloud_table->orderby('install_status', 'asc');
  775. $modulelist = $module_cloud_table->getall();
  776. if (!empty($modulelist)) {
  777. $modulenames = array();
  778. foreach ($modulelist as $module) {
  779. if (!empty($module['name']) && !in_array($module['name'], $modulenames)) {
  780. $modulenames[] = $module['name'];
  781. }
  782. }
  783. $module_recycle_support = array();
  784. if ($modulenames) {
  785. $modules_recycle = table('modules_recycle')->getByName($modulenames, '');
  786. if (!empty($modules_recycle)) {
  787. foreach ($modules_recycle as $info) {
  788. foreach ($module_support_types as $support => $value) {
  789. if (empty($module_recycle_support[$info['name']][$support])) {
  790. $module_recycle_support[$info['name']][$support] = $info[$support];
  791. }
  792. }
  793. }
  794. }
  795. }
  796. foreach ($modulelist as $key => $module) {
  797. $is_unset = true;
  798. foreach ($module_support_types as $support => $value) {
  799. if (!empty($module_recycle_support[$module['name']][$support])) {
  800. $module[$support] = $value['not_support'];
  801. }
  802. if ($module_support == 'all') {
  803. $module[MODULE_SUPPORT_SYSTEMWELCOME_NAME] = $value['not_support'];
  804. $modulelist[$key][MODULE_SUPPORT_SYSTEMWELCOME_NAME] = $value['not_support'];
  805. }
  806. if ($module[$support] == $value['support']) {
  807. $is_unset = false;
  808. }
  809. }
  810. if ($is_unset) {
  811. unset($modulelist[$key]);
  812. }
  813. }
  814. }
  815. $module_uninstall_total = module_uninstall_total($module_support);
  816. $pager = pagination(count($modulelist), 1, 15, '', array('ajaxcallback' => true, 'callbackfuncname' => 'loadMore'));
  817. }
  818. if ($do == 'init_modules_logo') {
  819. if (!pdo_fieldexists('modules', 'logo')) {
  820. pdo_query("ALTER TABLE " . tablename('modules') . " ADD `logo` varchar(250) NOT NULL DEFAULT '' ;");
  821. }
  822. $modules = pdo_fetchall("SELECT name FROM " . tablename('modules') . " WHERE issystem!=1");
  823. foreach ($modules as $key => $val) {
  824. if (file_exists (IA_ROOT . '/addons/' . $val['name'] . '/icon-custom.jpg')) {
  825. $val['logo'] = 'addons/' . $val['name'] . '/icon-custom.jpg';
  826. } else {
  827. $val['logo'] = 'addons/' . $val['name'] . '/icon.jpg';
  828. }
  829. pdo_update('modules', array('logo' => $val['logo']), array('name' => $val['name']));
  830. }
  831. iajax(0, '更新成功', url('module/manage-system/installed'));
  832. }
  833. template('module/manage-system');