人人商城

module.mod.php 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. function module_system() {
  8. return array(
  9. 'basic', 'news', 'music', 'service', 'userapi', 'recharge', 'images', 'video', 'voice', 'wxcard',
  10. 'custom', 'chats', 'paycenter', 'keyword', 'special', 'welcome', 'default', 'apply', 'reply', 'core', 'store',
  11. );
  12. }
  13. function module_types() {
  14. static $types = array(
  15. 'business' => array(
  16. 'name' => 'business',
  17. 'title' => '主要业务',
  18. 'desc' => ''
  19. ),
  20. 'customer' => array(
  21. 'name' => 'customer',
  22. 'title' => '客户关系',
  23. 'desc' => ''
  24. ),
  25. 'activity' => array(
  26. 'name' => 'activity',
  27. 'title' => '营销及活动',
  28. 'desc' => ''
  29. ),
  30. 'services' => array(
  31. 'name' => 'services',
  32. 'title' => '常用服务及工具',
  33. 'desc' => ''
  34. ),
  35. 'biz' => array(
  36. 'name' => 'biz',
  37. 'title' => '行业解决方案',
  38. 'desc' => ''
  39. ),
  40. 'enterprise' => array(
  41. 'name' => 'enterprise',
  42. 'title' => '企业应用',
  43. 'desc' => ''
  44. ),
  45. 'h5game' => array(
  46. 'name' => 'h5game',
  47. 'title' => 'H5游戏',
  48. 'desc' => ''
  49. ),
  50. 'other' => array(
  51. 'name' => 'other',
  52. 'title' => '其他',
  53. 'desc' => ''
  54. )
  55. );
  56. return $types;
  57. }
  58. function module_support_type() {
  59. $module_support_type = array(
  60. 'wxapp_support' => array(
  61. 'type' => WXAPP_TYPE_SIGN,
  62. 'support' => MODULE_SUPPORT_WXAPP,
  63. ),
  64. 'account_support' => array(
  65. 'type' => ACCOUNT_TYPE_SIGN,
  66. 'support' => MODULE_SUPPORT_ACCOUNT,
  67. ),
  68. 'welcome_support' => array(
  69. 'type' => WELCOMESYSTEM_TYPE_SIGN,
  70. 'support' => MODULE_SUPPORT_SYSTEMWELCOME,
  71. ),
  72. 'webapp_support' => array(
  73. 'type' => WEBAPP_TYPE_SIGN,
  74. 'support' => MODULE_SUPPORT_WEBAPP,
  75. ),
  76. 'phoneapp_support' => array(
  77. 'type' => PHONEAPP_TYPE_SIGN,
  78. 'support' => MODULE_SUPPORT_PHONEAPP,
  79. ),
  80. 'xzapp_support' => array(
  81. 'type' => XZAPP_TYPE_SIGN,
  82. 'support' => MODULE_SUPPORT_XZAPP,
  83. ),
  84. 'aliapp_support' => array(
  85. 'type' => ALIAPP_TYPE_SIGN,
  86. 'support' => MODULE_SUPPORT_ALIAPP,
  87. )
  88. );
  89. return $module_support_type;
  90. }
  91. function module_entries($name, $types = array(), $rid = 0, $args = null) {
  92. load()->func('communication');
  93. global $_W;
  94. $ts = array('rule', 'cover', 'menu', 'home', 'profile', 'shortcut', 'function', 'mine', 'system_welcome');
  95. if(empty($types)) {
  96. $types = $ts;
  97. } else {
  98. $types = array_intersect($types, $ts);
  99. }
  100. $bindings = pdo_getall('modules_bindings', array('module' => $name, 'entry' => $types), array(), '', 'displayorder DESC, eid ASC');
  101. $entries = array();
  102. foreach($bindings as $bind) {
  103. if(!empty($bind['call'])) {
  104. $response = ihttp_request(url('utility/bindcall', array('modulename' => $bind['module'], 'callname' => $bind['call'], 'args' => $args, 'uniacid' => $_W['uniacid'])), array(), $extra);
  105. if (is_error($response)) {
  106. continue;
  107. }
  108. $response = json_decode($response['content'], true);
  109. $ret = $response['message']['message'];
  110. if(is_array($ret)) {
  111. foreach($ret as $i => $et) {
  112. if (empty($et['url'])) {
  113. continue;
  114. }
  115. $et['url'] = $et['url'] . '&__title=' . urlencode($et['title']);
  116. $entries[$bind['entry']][] = array('eid' => 'user_' . $i, 'title' => $et['title'], 'do' => $et['do'], 'url' => $et['url'], 'from' => 'call', 'icon' => $et['icon'], 'displayorder' => $et['displayorder']);
  117. }
  118. }
  119. } else {
  120. if (in_array($bind['entry'], array('cover', 'home', 'profile', 'shortcut'))) {
  121. $url = murl('entry', array('eid' => $bind['eid']));
  122. }
  123. if (in_array($bind['entry'], array('menu', 'system_welcome'))) {
  124. $url = wurl("site/entry", array('eid' => $bind['eid']));
  125. }
  126. if($bind['entry'] == 'mine') {
  127. $url = $bind['url'];
  128. }
  129. if($bind['entry'] == 'rule') {
  130. $par = array('eid' => $bind['eid']);
  131. if (!empty($rid)) {
  132. $par['id'] = $rid;
  133. }
  134. $url = wurl("site/entry", $par);
  135. }
  136. if(empty($bind['icon'])) {
  137. $bind['icon'] = 'wi wi-appsetting';
  138. }
  139. if (!defined('SYSTEM_WELCOME_MODULE') && $bind['entry'] == 'system_welcome') {
  140. continue;
  141. }
  142. $entries[$bind['entry']][] = array('eid' => $bind['eid'], 'title' => $bind['title'], 'do' => $bind['do'], 'url' => $url, 'from' => 'define', 'icon' => $bind['icon'], 'displayorder' => $bind['displayorder'], 'direct' => $bind['direct']);
  143. }
  144. }
  145. return $entries;
  146. }
  147. function module_app_entries($name, $types = array(), $args = null) {
  148. global $_W;
  149. $ts = array('rule', 'cover', 'menu', 'home', 'profile', 'shortcut', 'function');
  150. if(empty($types)) {
  151. $types = $ts;
  152. } else {
  153. $types = array_intersect($types, $ts);
  154. }
  155. $bindings = pdo_getall('modules_bindings', array('module' => $name, 'entry' => $types));
  156. $entries = array();
  157. foreach($bindings as $bind) {
  158. if(!empty($bind['call'])) {
  159. $extra = array();
  160. $extra['Host'] = $_SERVER['HTTP_HOST'];
  161. load()->func('communication');
  162. $urlset = parse_url($_W['siteurl']);
  163. $urlset = pathinfo($urlset['path']);
  164. $response = ihttp_request($_W['sitescheme'] . '127.0.0.1/'. $urlset['dirname'] . '/' . url('utility/bindcall', array('modulename' => $bind['module'], 'callname' => $bind['call'], 'args' => $args, 'uniacid' => $_W['uniacid'])), array('W'=>base64_encode(iserializer($_W))), $extra);
  165. if (is_error($response)) {
  166. continue;
  167. }
  168. $response = json_decode($response['content'], true);
  169. $ret = $response['message'];
  170. if(is_array($ret)) {
  171. foreach($ret as $et) {
  172. $et['url'] = $et['url'] . '&__title=' . urlencode($et['title']);
  173. $entries[$bind['entry']][] = array('title' => $et['title'], 'url' => $et['url'], 'from' => 'call');
  174. }
  175. }
  176. } else {
  177. if($bind['entry'] == 'cover') {
  178. $url = murl("entry", array('eid' => $bind['eid']));
  179. }
  180. if($bind['entry'] == 'home') {
  181. $url = murl("entry", array('eid' => $bind['eid']));
  182. }
  183. if($bind['entry'] == 'profile') {
  184. $url = murl("entry", array('eid' => $bind['eid']));
  185. }
  186. if($bind['entry'] == 'shortcut') {
  187. $url = murl("entry", array('eid' => $bind['eid']));
  188. }
  189. $entries[$bind['entry']][] = array('title' => $bind['title'], 'do' => $bind['do'], 'url' => $url, 'from' => 'define');
  190. }
  191. }
  192. return $entries;
  193. }
  194. function module_entry($eid) {
  195. $sql = "SELECT * FROM " . tablename('modules_bindings') . " WHERE `eid`=:eid";
  196. $pars = array();
  197. $pars[':eid'] = $eid;
  198. $entry = pdo_fetch($sql, $pars);
  199. if(empty($entry)) {
  200. return error(1, '模块菜单不存在');
  201. }
  202. $module = module_fetch($entry['module']);
  203. if(empty($module)) {
  204. return error(2, '模块不存在');
  205. }
  206. $querystring = array(
  207. 'do' => $entry['do'],
  208. 'm' => $entry['module'],
  209. );
  210. if (!empty($entry['state'])) {
  211. $querystring['state'] = $entry['state'];
  212. }
  213. $entry['url'] = murl('entry', $querystring);
  214. $entry['url_show'] = murl('entry', $querystring, true, true);
  215. return $entry;
  216. }
  217. function module_build_form($name, $rid, $option = array()) {
  218. $rid = intval($rid);
  219. $m = WeUtility::createModule($name);
  220. if(!empty($m)) {
  221. return $m->fieldsFormDisplay($rid, $option);
  222. }else {
  223. return null;
  224. }
  225. }
  226. function module_save_group_package($package) {
  227. global $_W;
  228. load()->model('user');
  229. load()->model('cache');
  230. if (empty($package['name'])) {
  231. return error(-1, '请输入套餐名');
  232. }
  233. if (user_is_vice_founder()) {
  234. $package['owner_uid'] = $_W['uid'];
  235. }
  236. if (!empty($package['modules'])) {
  237. $package['modules'] = iserializer($package['modules']);
  238. }
  239. if (!empty($package['templates'])) {
  240. $templates = array();
  241. foreach ($package['templates'] as $template) {
  242. $templates[] = $template['id'];
  243. }
  244. $package['templates'] = iserializer($templates);
  245. }
  246. if (!empty($package['id'])) {
  247. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'id <>' => $package['id'], 'name' => $package['name']));
  248. } else {
  249. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'name' => $package['name']));
  250. }
  251. if (!empty($name_exist)) {
  252. return error(-1, '套餐名已存在');
  253. }
  254. if (!empty($package['id'])) {
  255. pdo_update('uni_group', $package, array('id' => $package['id']));
  256. cache_build_account_modules();
  257. } else {
  258. pdo_insert('uni_group', $package);
  259. }
  260. cache_build_uni_group();
  261. return error(0, '添加成功');
  262. }
  263. function module_fetch($name, $enabled = true) {
  264. global $_W;
  265. $cachekey = cache_system_key('module_info', array('module_name' => $name));
  266. $module = cache_load($cachekey);
  267. if (empty($module)) {
  268. $module_info = table('modules')->getByName($name);
  269. if (empty($module_info)) {
  270. return array();
  271. }
  272. if (!empty($module_info['subscribes'])) {
  273. $module_info['subscribes'] = (array)unserialize ($module_info['subscribes']);
  274. }
  275. if (!empty($module_info['handles'])) {
  276. $module_info['handles'] = (array)unserialize ($module_info['handles']);
  277. }
  278. $module_info['isdisplay'] = 1;
  279. if (file_exists (IA_ROOT . '/addons/' . $module_info['name'] . '/icon-custom.jpg')) {
  280. $module_info['logo'] = tomedia (IA_ROOT . '/addons/' . $module_info['name'] . '/icon-custom.jpg') . "?v=" . time ();
  281. } else {
  282. $module_info['logo'] = tomedia (IA_ROOT . '/addons/' . $module_info['name'] . '/icon.jpg') . "?v=" . time ();
  283. }
  284. if (file_exists(IA_ROOT . '/addons/' . $module_info['name'] . '/preview-custom.jpg')) {
  285. $module_info['preview'] = tomedia(IA_ROOT . '/addons/' . $module_info['name'] . '/preview-custom.jpg');
  286. } else {
  287. $module_info['preview'] = tomedia(IA_ROOT . '/addons/' . $module_info['name'] . '/preview.jpg');
  288. }
  289. $module_info['main_module'] = pdo_getcolumn ('modules_plugin', array ('name' => $module_info['name']), 'main_module');
  290. if (!empty($module_info['main_module'])) {
  291. $main_module_info = module_fetch ($module_info['main_module']);
  292. $module_info['main_module_logo'] = $main_module_info['logo'];
  293. } else {
  294. $module_info['plugin_list'] = pdo_getall ('modules_plugin', array ('main_module' => $module_info['name']), array (), 'name');
  295. if (!empty($module_info['plugin_list'])) {
  296. $module_info['plugin_list'] = array_keys ($module_info['plugin_list']);
  297. }
  298. }
  299. if ($module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT && $module_info[MODULE_SUPPORT_PHONEAPP_NAME] != MODULE_SUPPORT_PHONEAPP && $module_info[MODULE_SUPPORT_XZAPP_NAME] != MODULE_SUPPORT_XZAPP && $module_info['wxapp_support'] != MODULE_SUPPORT_WXAPP && $module_info['webapp_support'] != MODULE_SUPPORT_WEBAPP && $module_info['welcome_support'] != MODULE_SUPPORT_SYSTEMWELCOME) {
  300. $module_info[MODULE_SUPPORT_ACCOUNT_NAME] = MODULE_SUPPORT_ACCOUNT;
  301. }
  302. $module_receive_ban = (array)setting_load('module_receive_ban');
  303. if (is_array($module_receive_ban['module_receive_ban']) && in_array($name, $module_receive_ban['module_receive_ban'])) {
  304. $module_info['is_receive_ban'] = true;
  305. }
  306. $module_ban = (array)setting_load('module_ban');
  307. if (is_array($module_ban['module_ban']) && in_array($name, $module_ban['module_ban'])) {
  308. $module_info['is_ban'] = true;
  309. }
  310. $module_upgrade = (array)setting_load('module_upgrade');
  311. if (is_array($module_upgrade['module_upgrade']) && in_array($name, array_keys($module_upgrade['module_upgrade']))) {
  312. $module_info['is_upgrade'] = true;
  313. }
  314. $module_is_delete = table('modules_recycle')->getByName($name);
  315. if (!empty($module_is_delete)) {
  316. $module_info['is_delete'] = true;
  317. }
  318. $module = $module_info;
  319. cache_write($cachekey, $module_info);
  320. }
  321. if (!empty($enabled)) {
  322. if (!empty($module_info['is_delete'])) {
  323. return array();
  324. }
  325. }
  326. if (!empty($module) && !empty($_W['uniacid'])) {
  327. $setting_cachekey = cache_system_key('module_setting', array('module_name' => $name, 'uniacid' => $_W['uniacid']));
  328. $setting = cache_load($setting_cachekey);
  329. if (empty($setting)) {
  330. $setting = pdo_get('uni_account_modules', array('module' => $name, 'uniacid' => $_W['uniacid']));
  331. $setting = empty($setting) ? array('module' => $name) : $setting;
  332. cache_write($setting_cachekey, $setting);
  333. }
  334. $module['config'] = !empty($setting['settings']) ? iunserializer($setting['settings']) : array();
  335. $module['enabled'] = $module['issystem'] || !isset($setting['enabled']) ? 1 : $setting['enabled'];
  336. $module['displayorder'] = $setting['displayorder'];
  337. $module['shortcut'] = $setting['shortcut'];
  338. }
  339. return $module;
  340. }
  341. function module_permission_fetch($name) {
  342. $module = module_fetch($name);
  343. $data = array();
  344. if($module['settings']) {
  345. $data[] = array('title' => '参数设置', 'permission' => $name.'_settings');
  346. }
  347. if($module['isrulefields']) {
  348. $data[] = array('title' => '回复规则列表', 'permission' => $name.'_rule');
  349. }
  350. $entries = module_entries($name);
  351. if(!empty($entries['home'])) {
  352. $data[] = array('title' => '微站首页导航', 'permission' => $name.'_home');
  353. }
  354. if(!empty($entries['profile'])) {
  355. $data[] = array('title' => '个人中心导航', 'permission' => $name.'_profile');
  356. }
  357. if(!empty($entries['shortcut'])) {
  358. $data[] = array('title' => '快捷菜单', 'permission' => $name.'_shortcut');
  359. }
  360. if(!empty($entries['cover'])) {
  361. foreach($entries['cover'] as $cover) {
  362. $data[] = array('title' => $cover['title'], 'permission' => $name.'_cover_'.$cover['do']);
  363. }
  364. }
  365. if(!empty($entries['menu'])) {
  366. foreach($entries['menu'] as $menu) {
  367. $data[$menu['do']] = array('title' => $menu['title'], 'permission' => $name.'_menu_'.$menu['do']);
  368. }
  369. }
  370. unset($entries);
  371. if(!empty($module['permissions'])) {
  372. $module['permissions'] = (array)iunserializer($module['permissions']);
  373. foreach ($module['permissions'] as $permission) {
  374. if (!empty($permission['parent']) && !empty($data[$permission['parent']])) {
  375. $sub_permission = array(
  376. 'title' => $permission['title'],
  377. 'permission' => $name . '_menu_' . $permission['parent'] . '_' . $permission['permission'],
  378. );
  379. if (empty($data[$permission['parent']]['sub_permission'])) {
  380. $data[$permission['parent']]['sub_permission'] = array($sub_permission);
  381. } else {
  382. array_push($data[$permission['parent']]['sub_permission'], $sub_permission);
  383. }
  384. }
  385. $data[] = array('title' => $permission['title'], 'permission' => $name . '_permission_' . $permission['permission']);
  386. }
  387. }
  388. return $data;
  389. }
  390. function module_get_plugin_list($module_name) {
  391. $module_info = module_fetch($module_name);
  392. if (!empty($module_info['plugin_list']) && is_array($module_info['plugin_list'])) {
  393. $plugin_list = array();
  394. foreach ($module_info['plugin_list'] as $plugin) {
  395. $plugin_info = module_fetch($plugin);
  396. if (!empty($plugin_info)) {
  397. $plugin_list[$plugin] = $plugin_info;
  398. }
  399. }
  400. return $plugin_list;
  401. } else {
  402. return array();
  403. }
  404. }
  405. function module_status($module) {
  406. load()->model('cloud');
  407. $result = array(
  408. 'upgrade' => array(
  409. 'has_upgrade' => false,
  410. ),
  411. 'ban' => false,
  412. );
  413. $module_cloud_info = table('modules_cloud')->getByName($module);
  414. if (!empty($module_cloud_info['has_new_version']) || !empty($module_cloud_info['has_new_branch'])) {
  415. $result['upgrade'] = array(
  416. 'has_upgrade' => true,
  417. 'name' => $module_cloud_info['title'],
  418. 'version' => $module_cloud_info['version'],
  419. );
  420. }
  421. if (!empty($module_cloud_info['is_ban'])) {
  422. $result['ban'] = true;
  423. }
  424. return $result;
  425. }
  426. function module_exist_in_account($module_name, $uniacid) {
  427. global $_W;
  428. $result = false;
  429. $module_name = trim($module_name);
  430. $uniacid = intval($uniacid);
  431. if (empty($module_name) || empty($uniacid)) {
  432. return $result;
  433. }
  434. $founders = explode(',', $_W['config']['setting']['founder']);
  435. $owner_uid = pdo_getcolumn('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'), 'uid');
  436. if (!empty($owner_uid) && !in_array($owner_uid, $founders)) {
  437. if (IMS_FAMILY == 'x') {
  438. $site_store_buy_goods = uni_site_store_buy_goods($uniacid);
  439. } else {
  440. $site_store_buy_goods = array();
  441. }
  442. $account_table = table('account');
  443. $uni_modules = $account_table->accountGroupModules($uniacid);
  444. $user_modules = user_modules($owner_uid);
  445. $modules = array_merge(array_keys($user_modules), $uni_modules, $site_store_buy_goods);
  446. $result = in_array($module_name, $modules) ? true : false;
  447. } else {
  448. $result = true;
  449. }
  450. return $result;
  451. }
  452. function module_get_user_account_list($uid, $module_name) {
  453. $accounts_list = array();
  454. $uid = intval($uid);
  455. $module_name = trim($module_name);
  456. if (empty($uid) || empty($module_name)) {
  457. return $accounts_list;
  458. }
  459. $module_info = module_fetch($module_name);
  460. if (empty($module_info)) {
  461. return $accounts_list;
  462. }
  463. $account_users_info = table('account')->userOwnedAccount($uid);
  464. if (empty($account_users_info)) {
  465. return $accounts_list;
  466. }
  467. $accounts = array();
  468. foreach ($account_users_info as $account) {
  469. if (empty($account['uniacid'])) {
  470. continue;
  471. }
  472. $uniacid = 0;
  473. if (($account['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) && $module_info[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT) {
  474. $uniacid = $account['uniacid'];
  475. } elseif ($account['type'] == ACCOUNT_TYPE_APP_NORMAL && $module_info['wxapp_support'] == MODULE_SUPPORT_WXAPP) {
  476. $uniacid = $account['uniacid'];
  477. } elseif (($account['type'] == ACCOUNT_TYPE_XZAPP_NORMAL || $account['type'] == ACCOUNT_TYPE_XZAPP_AUTH) && $module_info[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP) {
  478. $uniacid = $account['uniacid'];
  479. } elseif (($account['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL && $module_info[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP)) {
  480. $uniacid = $account['uniacid'];
  481. } elseif (($account['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL && $module_info[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP)) {
  482. $uniacid = $account['uniacid'];
  483. } elseif (($account['type'] == ACCOUNT_TYPE_ALIAPP_NORMAL && $module_info[MODULE_SUPPORT_ALIAPP_NAME] == MODULE_SUPPORT_ALIAPP)) {
  484. $uniacid = $account['uniacid'];
  485. }
  486. if (!empty($uniacid)) {
  487. if (module_exist_in_account($module_name, $uniacid)) {
  488. $accounts_list[$uniacid] = $account;
  489. }
  490. }
  491. }
  492. return $accounts_list;
  493. }
  494. function module_link_uniacid_fetch($uid, $module_name) {
  495. $result = array();
  496. $uid = intval($uid);
  497. $module_name = trim($module_name);
  498. if (empty($uid) || empty($module_name)) {
  499. return $result;
  500. }
  501. $accounts_list = module_get_user_account_list($uid, $module_name);
  502. if (empty($accounts_list)) {
  503. return $result;
  504. }
  505. $accounts_link_result = array();
  506. foreach ($accounts_list as $key => $account_value) {
  507. if (in_array($account_value['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_ALIAPP_NORMAL))) {
  508. $account_value['versions'] = miniapp_version_all($account_value['uniacid']);
  509. if (empty($account_value['versions'])) {
  510. $accounts_link_result[$key] = $account_value;
  511. continue;
  512. }
  513. foreach ($account_value['versions'] as $version_key => $version_value) {
  514. if (empty($version_value['modules'])) {
  515. continue;
  516. }
  517. if ($version_value['modules'][0]['name'] != $module_name) {
  518. continue;
  519. }
  520. if (empty($version_value['modules'][0]['account']) || !is_array($version_value['modules'][0]['account'])) {
  521. $accounts_link_result[$key] = $account_value;
  522. continue;
  523. }
  524. if (!empty($version_value['modules'][0]['account']['uniacid'])) {
  525. $accounts_link_result[$version_value['modules'][0]['account']['uniacid']][] = array(
  526. 'uniacid' => $key,
  527. 'version' => $version_value['version'],
  528. 'version_id' => $version_value['id'],
  529. 'name' => $account_value['name'],
  530. );
  531. unset($account_value['versions'][$version_key]);
  532. }
  533. }
  534. } elseif ($account_value['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account_value['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH || $account_value['type']== ACCOUNT_TYPE_XZAPP_NORMAL || $account_value['type'] == ACCOUNT_TYPE_XZAPP_AUTH) {
  535. if (empty($accounts_link_result[$key])) {
  536. $accounts_link_result[$key] = $account_value;
  537. } else {
  538. $link_wxapp = $accounts_link_result[$key];
  539. $accounts_link_result[$key] = $account_value;
  540. $accounts_link_result[$key]['link_wxapp'] = $link_wxapp;
  541. }
  542. } else {
  543. if (empty($accounts_link_result[$key])) {
  544. $accounts_link_result[$key] = $account_value;
  545. }
  546. }
  547. }
  548. if (!empty($accounts_link_result)) {
  549. foreach ($accounts_link_result as $link_key => $link_value) {
  550. if (in_array($link_value['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  551. $link_value['type_name'] = ACCOUNT_TYPE_SIGN;
  552. } elseif (in_array($link_value['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH))) {
  553. $link_value['type_name'] = WXAPP_TYPE_SIGN;
  554. } elseif ($link_value['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  555. $link_value['type_name'] = WEBAPP_TYPE_SIGN;
  556. }elseif ($link_value['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  557. $link_value['type_name'] = PHONEAPP_TYPE_SIGN;
  558. }elseif ($link_value['type'] == ACCOUNT_TYPE_XZAPP_NORMAL) {
  559. $link_value['type_name'] = XZAPP_TYPE_SIGN;
  560. }elseif ($link_value['type'] == ACCOUNT_TYPE_ALIAPP_NORMAL) {
  561. $link_value['type_name'] = ALIAPP_TYPE_SIGN;
  562. }
  563. if (in_array($link_value['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH)) && !empty($link_value['link_wxapp']) && is_array($link_value['link_wxapp'])) {
  564. foreach ($link_value['link_wxapp'] as $value) {
  565. $result[] = array(
  566. 'app_name' => $link_value['name'],
  567. 'wxapp_name' => $value['name'] . ' ' . $value['version'],
  568. 'uniacid' => $link_value['uniacid'],
  569. 'version_id' => $value['version_id'],
  570. 'type_name' => $link_value['type_name'],
  571. 'account_name' => $link_value['name'],
  572. );
  573. }
  574. } elseif ($link_value['type'] == ACCOUNT_TYPE_APP_NORMAL && !empty($link_value['versions']) && is_array($link_value['versions'])) {
  575. foreach ($link_value['versions'] as $value) {
  576. $result[] = array(
  577. 'app_name' => '',
  578. 'wxapp_name' => $link_value['name'] . ' ' . $value['version'],
  579. 'uniacid' => $link_value['uniacid'],
  580. 'version_id' => $value['id'],
  581. 'type_name' => $link_value['type_name'],
  582. 'account_name' => $link_value['name'],
  583. );
  584. }
  585. } else {
  586. $result[] = array(
  587. 'app_name' => $link_value['name'],
  588. 'wxapp_name' => '',
  589. 'uniacid' => $link_value['uniacid'],
  590. 'version_id' => '',
  591. 'type_name' => $link_value['type_name'],
  592. 'account_name' => $link_value['name'],
  593. );
  594. }
  595. }
  596. }
  597. return $result;
  598. }
  599. function module_link_uniacid_info($module_name) {
  600. if (empty($module_name)) {
  601. return array();
  602. }
  603. $result = table('uni_account_modules')->where('module', $module_name)->getall();
  604. if (!empty($result)) {
  605. foreach ($result as $key => $value) {
  606. $result[$key]['settings'] = iunserializer($value['settings']);
  607. if (empty($result[$key]['settings']) || (empty($result[$key]['settings']['link_uniacid']) && empty($result[$key]['settings']['passive_link_uniacid']))) {
  608. unset($result[$key]);
  609. }
  610. }
  611. return $result;
  612. }
  613. return array();
  614. }
  615. function module_save_switch($module_name, $uniacid = 0, $version_id = 0) {
  616. global $_W, $_GPC;
  617. load()->model('visit');
  618. if (empty($_GPC['__switch'])) {
  619. $_GPC['__switch'] = random(5);
  620. }
  621. $cache_key = cache_system_key('last_account', array('switch' => $_GPC['__switch']));
  622. $cache_lastaccount = (array)cache_load($cache_key);
  623. if (empty($cache_lastaccount)) {
  624. $cache_lastaccount = array(
  625. $module_name => array(
  626. 'module_name' => $module_name,
  627. 'uniacid' => $uniacid,
  628. 'version_id' => $version_id
  629. )
  630. );
  631. } else {
  632. $cache_lastaccount[$module_name] = array(
  633. 'module_name' => $module_name,
  634. 'uniacid' => $uniacid,
  635. 'version_id' => $version_id
  636. );
  637. }
  638. visit_system_update(array('modulename' => $module_name, 'uid' => $_W['uid']));
  639. cache_write($cache_key, $cache_lastaccount);
  640. isetcookie('__switch', $_GPC['__switch'], 7 * 86400);
  641. return true;
  642. }
  643. function module_last_switch($module_name) {
  644. global $_GPC;
  645. $module_name = trim($module_name);
  646. if (empty($module_name)) {
  647. return array();
  648. }
  649. $cache_key = cache_system_key('last_account', array('switch' => $_GPC['__switch']));
  650. $cache_lastaccount = (array)cache_load($cache_key);
  651. return $cache_lastaccount[$module_name];
  652. }
  653. function module_clerk_info($module_name) {
  654. $user_permissions = array();
  655. $module_name = trim($module_name);
  656. if (empty($module_name)) {
  657. return $user_permissions;
  658. }
  659. $user_permissions = table('users_permission')->getClerkPermission($module_name);
  660. if (!empty($user_permissions)) {
  661. foreach ($user_permissions as $key => $value) {
  662. $user_permissions[$key]['user_info'] = user_single($value['uid']);
  663. }
  664. }
  665. return $user_permissions;
  666. }
  667. function module_rank_top($module_name) {
  668. global $_W;
  669. if (empty($module_name)) {
  670. return false;
  671. }
  672. $result = table('modules_rank')->setTop($module_name);
  673. return empty($result) ? true : false;
  674. }
  675. function module_installed_list($type = '') {
  676. global $_W;
  677. $module_list = array();
  678. $user_has_module = user_modules($_W['uid']);
  679. if (empty($user_has_module)) {
  680. return $module_list;
  681. }
  682. $module_support_type = module_support_type();
  683. foreach ($user_has_module as $modulename => $module) {
  684. if ((!empty($module['issystem']) && $module['name'] != 'we7_coupon')) {
  685. continue;
  686. }
  687. foreach ($module_support_type as $support_name => $support) {
  688. if ($module[$support_name] == $support['support']) {
  689. $module_list[$support['type']][$modulename] = $module;
  690. }
  691. }
  692. }
  693. if (!empty($type)) {
  694. return (array)$module_list[$type];
  695. } else {
  696. return $module_list;
  697. }
  698. }
  699. function module_uninstall_list() {
  700. $uninstall_modules = table('modules_cloud')->getUninstallModule();
  701. if (!empty($uninstall_modules)) {
  702. array_walk($uninstall_modules, function(&$row, $key) {
  703. if ($row[MODULE_SUPPORT_WXAPP_NAME] == MODULE_SUPPORT_WXAPP) {
  704. $support = MODULE_SUPPORT_WXAPP_NAME;
  705. } else {
  706. $support = MODULE_SUPPORT_ACCOUNT_NAME;
  707. }
  708. $row['link'] = url('module/manage-system/install', array('module_name' => $row['name'], 'support' => $support));
  709. });
  710. }
  711. return $uninstall_modules;
  712. }
  713. function module_uninstall_total($type) {
  714. $type_list = module_support_type();
  715. if (!isset($type_list["{$type}_support"])) {
  716. return 0;
  717. }
  718. $total = table('modules_cloud')->getUninstallTotalBySupportType($type);
  719. return $total;
  720. }
  721. function module_upgrade_list() {
  722. $result = array();
  723. $module_list = user_modules($_W['uid']);
  724. if (empty($module_list)) {
  725. return $result;
  726. }
  727. $upgrade_modules = table('modules_cloud')->getUpgradeByModuleNameList(array_keys($module_list));
  728. if (empty($upgrade_modules)) {
  729. return $result;
  730. }
  731. $modules_ignore = table('modules_ignore')->where('name', array_keys($upgrade_modules))->getall('name');
  732. foreach ($upgrade_modules as $modulename => &$module) {
  733. if (!empty($modules_ignore[$modulename])) {
  734. if (ver_compare($modules_ignore[$modulename]['version'], $module['version']) >= 0) {
  735. $module['is_ignore'] = 1;
  736. }
  737. }
  738. $module['link'] = url('module/manage-system/module_detail', array('name' => $module['name'], 'show' => 'upgrade'));
  739. }
  740. unset($module);
  741. return $upgrade_modules;
  742. }
  743. function module_upgrade_total($type) {
  744. $type_list = module_support_type();
  745. if (!isset($type_list["{$type}_support"])) {
  746. return 0;
  747. }
  748. $total = table('modules_cloud')->getUpgradeTotalBySupportType($type);
  749. return $total;
  750. }
  751. function module_upgrade_info($modulelist = array()) {
  752. load()->model('cloud');
  753. load()->model('extension');
  754. $result = array();
  755. cloud_prepare();
  756. $cloud_m_query_module = cloud_m_query();
  757. if (is_error($cloud_m_query_module)) {
  758. return array();
  759. }
  760. $pirate_apps = $cloud_m_query_module['pirate_apps'];
  761. unset($cloud_m_query_module['pirate_apps']);
  762. $manifest_cloud_list = array();
  763. foreach ($cloud_m_query_module as $modulename => $manifest_cloud) {
  764. $manifest = array(
  765. 'application' => array(
  766. 'name' => $modulename,
  767. 'title' => $manifest_cloud['title'],
  768. 'version' => $manifest_cloud['version'],
  769. 'logo' => $manifest_cloud['thumb'],
  770. 'version' => $manifest_cloud['version'],
  771. 'last_upgrade_time' => $manifest_cloud['last_upgrade_time'],
  772. ),
  773. 'platform' => array(
  774. 'supports' => array()
  775. ),
  776. );
  777. if ($manifest_cloud['site_branch']['app_support'] == MODULE_SUPPORT_ACCOUNT) {
  778. $manifest['platform']['supports'][] = 'account';
  779. }
  780. if ($manifest_cloud['site_branch']['wxapp_support'] == MODULE_SUPPORT_WXAPP) {
  781. $manifest['platform']['supports'][] = 'wxapp';
  782. }
  783. if ($manifest_cloud['site_branch']['xzapp_support'] == MODULE_SUPPORT_XZAPP) {
  784. $manifest['platform']['supports'][] = 'xzapp';
  785. }
  786. if ($manifest_cloud['site_branch']['aliapp_support'] == MODULE_SUPPORT_ALIAPP) {
  787. $manifest['platform']['supports'][] = 'aliapp';
  788. }
  789. if ($manifest_cloud['site_branch']['webapp_support'] == MODULE_SUPPORT_WEBAPP) {
  790. $manifest['platform']['supports'][] = 'webapp';
  791. }
  792. if ($manifest_cloud['site_branch']['android_support'] == MODULE_SUPPORT_PHONEAPP ||
  793. $manifest_cloud['site_branch']['ios_aupport'] == MODULE_SUPPORT_PHONEAPP) {
  794. $manifest['platform']['supports'][] = 'phoneapp';
  795. }
  796. if ($manifest_cloud['site_branch']['system_welcome_support'] == MODULE_SUPPORT_SYSTEMWELCOME) {
  797. $manifest['platform']['supports'][] = 'welcome';
  798. }
  799. if (empty($manifest['platform']['supports'])) {
  800. continue;
  801. }
  802. $manifest['branches'] = $manifest_cloud['branches'];
  803. $manifest['site_branch'] = $manifest_cloud['site_branch'];
  804. $manifest['cloud_id'] = $manifest_cloud['id'];
  805. $manifest_cloud_list[$modulename] = $manifest;
  806. }
  807. if (empty($modulelist)) {
  808. $modulelist = table('modules')->searchWithType('system', '<>')->getall('name');
  809. }
  810. foreach ($modulelist as $modulename => $module) {
  811. if (!empty($module['issystem'])) {
  812. unset($modulelist[$modulename]);
  813. continue;
  814. }
  815. $module_upgrade_data = array(
  816. 'name' => $modulename,
  817. 'has_new_version' => 0,
  818. 'has_new_branch' => 0,
  819. );
  820. if (!empty($pirate_apps) && in_array($modulename, $pirate_apps)) {
  821. $module_upgrade_data['is_ban'] = 1;
  822. }
  823. $manifest = ext_module_manifest($modulename);
  824. if (!empty($manifest)) {
  825. $module_upgrade_data['install_status'] = MODULE_LOCAL_INSTALL;
  826. } elseif ($manifest_cloud_list[$modulename]) {
  827. $module_upgrade_data['install_status'] = MODULE_CLOUD_INSTALL;
  828. $manifest = $manifest_cloud_list[$modulename];
  829. } else {
  830. $module_upgrade_data['install_status'] = MODULE_LOCAL_INSTALL;
  831. }
  832. $module_upgrade_data['logo'] = $manifest['application']['logo'];
  833. $module_upgrade_data['version'] = $manifest['application']['version'];
  834. $module_upgrade_data['title'] = $manifest['application']['title'];
  835. $module_upgrade_data['title_initial'] = get_first_pinyin($manifest['application']['title']);
  836. unset($manifest_cloud_list[$modulename]);
  837. if (version_compare($module['version'], $manifest['application']['version']) == '-1') {
  838. $module_upgrade_data['has_new_version'] = 1;
  839. $module_upgrade_data['lastupdatetime'] = TIMESTAMP;
  840. $result[$modulename] = array(
  841. 'name' => $modulename,
  842. 'new_version' => 1,
  843. 'best_version' => $manifest['application']['version'],
  844. );
  845. }
  846. if ($module_upgrade_data['install_status'] == MODULE_LOCAL_INSTALL && empty($module_upgrade_data['has_new_version'])) {
  847. continue;
  848. }
  849. if (!empty($manifest['branches'])) {
  850. foreach ($manifest['branches'] as &$branch) {
  851. if ($branch['displayorder'] > $manifest['site_branch']['displayorder'] || ($branch['displayorder'] == $manifest['site_branch']['displayorder'] && $manifest['site_branch']['id'] < intval($branch['id']))) {
  852. $module_upgrade_data['has_new_branch'] = 1;
  853. $result[$modulename]['new_branch'] = 1;
  854. }
  855. }
  856. }
  857. if (!empty($manifest['platform']['supports'])) {
  858. foreach (array('account', 'wxapp', 'webapp', 'phoneapp', 'welcome', 'xzapp', 'aliapp') as $support) {
  859. if (in_array($support, $manifest['platform']['supports'])) {
  860. $module_upgrade_data["{$support}_support"] = MODULE_SUPPORT_ACCOUNT;
  861. } else {
  862. $module_upgrade_data["{$support}_support"] = MODULE_NONSUPPORT_ACCOUNT;
  863. }
  864. }
  865. }
  866. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  867. if (empty($module_cloud_upgrade)) {
  868. pdo_insert('modules_cloud', $module_upgrade_data);
  869. } else {
  870. pdo_update('modules_cloud', $module_upgrade_data, array('name' => $modulename));
  871. }
  872. }
  873. if (!empty($manifest_cloud_list)) {
  874. foreach ($manifest_cloud_list as $modulename => $manifest) {
  875. $module_upgrade_data = array(
  876. 'name' => $modulename,
  877. 'has_new_version' => 0,
  878. 'has_new_branch' => 0,
  879. 'install_status' => MODULE_CLOUD_UNINSTALL,
  880. 'logo' => $manifest['application']['logo'],
  881. 'version' => $manifest['application']['version'],
  882. 'title' => $manifest['application']['title'],
  883. 'title_initial' => get_first_pinyin($manifest['application']['title']),
  884. 'lastupdatetime' => $manifest['application']['last_upgrade_time'],
  885. 'cloud_id' => $manifest['cloud_id'],
  886. );
  887. if (!empty($manifest['platform']['supports'])) {
  888. foreach (array('account', 'wxapp', 'webapp', 'phoneapp', 'welcome', 'xzapp', 'aliapp') as $support) {
  889. if (in_array($support, $manifest['platform']['supports'])) {
  890. $module_upgrade_data["{$support}_support"] = MODULE_SUPPORT_ACCOUNT;
  891. } else {
  892. $module_upgrade_data["{$support}_support"] = MODULE_NONSUPPORT_ACCOUNT;
  893. }
  894. }
  895. }
  896. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  897. if (empty($module_cloud_upgrade)) {
  898. pdo_insert('modules_cloud', $module_upgrade_data);
  899. } else {
  900. pdo_update('modules_cloud', $module_upgrade_data, array('name' => $modulename));
  901. }
  902. }
  903. }
  904. return $result;
  905. }
  906. function module_recycle_fetch($modulename) {
  907. return table('modules_recycle')->getByName($modulename);
  908. }
  909. function module_check_notinstalled_support($module, $manifest_support) {
  910. if (empty($manifest_support)) {
  911. return array();
  912. }
  913. $all_support = array('account', 'wxapp', 'webapp', 'phoneapp', 'welcome', 'xzapp', 'aliapp');
  914. $notinstalled_support = array();
  915. $has_notinstalled_support = false;
  916. foreach ($manifest_support as &$s) {
  917. if ($s == 'app') {
  918. $s = 'account';
  919. }
  920. }
  921. foreach ($all_support as $support) {
  922. if (in_array($support, $manifest_support) && $module["{$support}_support"] != MODULE_SUPPORT_ACCOUNT) {
  923. $has_notinstalled_support = true;
  924. $notinstalled_support["{$support}_support"] = MODULE_SUPPORT_ACCOUNT;
  925. } else {
  926. $notinstalled_support["{$support}_support"] = MODULE_NONSUPPORT_ACCOUNT;
  927. }
  928. }
  929. if ($has_notinstalled_support) {
  930. return $notinstalled_support;
  931. } else {
  932. return array();
  933. }
  934. }