module.mod.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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. 'type_name' => '微信小程序',
  63. 'support' => MODULE_SUPPORT_WXAPP,
  64. 'not_support' => MODULE_NONSUPPORT_WXAPP,
  65. 'store_type' => STORE_TYPE_WXAPP_MODULE,
  66. ),
  67. 'account_support' => array(
  68. 'type' => ACCOUNT_TYPE_SIGN,
  69. 'type_name' => '公众号',
  70. 'support' => MODULE_SUPPORT_ACCOUNT,
  71. 'not_support' => MODULE_NONSUPPORT_ACCOUNT,
  72. 'store_type' => STORE_TYPE_MODULE,
  73. ),
  74. 'welcome_support' => array(
  75. 'type' => WELCOMESYSTEM_TYPE_SIGN,
  76. 'type_name' => '系统首页',
  77. 'support' => MODULE_SUPPORT_SYSTEMWELCOME,
  78. 'not_support' => MODULE_NONSUPPORT_SYSTEMWELCOME,
  79. ),
  80. 'webapp_support' => array(
  81. 'type' => WEBAPP_TYPE_SIGN,
  82. 'type_name' => 'PC',
  83. 'support' => MODULE_SUPPORT_WEBAPP,
  84. 'not_support' => MODULE_NOSUPPORT_WEBAPP,
  85. 'store_type' => STORE_TYPE_WEBAPP_MODULE,
  86. ),
  87. 'phoneapp_support' => array(
  88. 'type' => PHONEAPP_TYPE_SIGN,
  89. 'type_name' => 'APP',
  90. 'support' => MODULE_SUPPORT_PHONEAPP,
  91. 'not_support' => MODULE_NOSUPPORT_PHONEAPP,
  92. 'store_type' => STORE_TYPE_PHONEAPP_MODULE,
  93. ),
  94. 'xzapp_support' => array(
  95. 'type' => XZAPP_TYPE_SIGN,
  96. 'type_name' => '熊掌号',
  97. 'support' => MODULE_SUPPORT_XZAPP,
  98. 'not_support' => MODULE_NOSUPPORT_XZAPP,
  99. 'store_type' => STORE_TYPE_XZAPP_MODULE,
  100. ),
  101. 'aliapp_support' => array(
  102. 'type' => ALIAPP_TYPE_SIGN,
  103. 'type_name' => '支付宝小程序',
  104. 'support' => MODULE_SUPPORT_ALIAPP,
  105. 'not_support' => MODULE_NOSUPPORT_ALIAPP,
  106. 'store_type' => STORE_TYPE_ALIAPP_MODULE,
  107. ),
  108. 'baiduapp_support' => array(
  109. 'type' => BAIDUAPP_TYPE_SIGN,
  110. 'type_name' => '百度小程序',
  111. 'support' => MODULE_SUPPORT_BAIDUAPP,
  112. 'not_support' => MODULE_NOSUPPORT_BAIDUAPP,
  113. 'store_type' => STORE_TYPE_BAIDUAPP_MODULE,
  114. ),
  115. 'toutiaoapp_support' => array(
  116. 'type' => TOUTIAOAPP_TYPE_SIGN,
  117. 'type_name' => '头条小程序',
  118. 'support' => MODULE_SUPPORT_TOUTIAOAPP,
  119. 'not_support' => MODULE_NOSUPPORT_TOUTIAOAPP,
  120. 'store_type' => STORE_TYPE_TOUTIAOAPP_MODULE,
  121. )
  122. );
  123. return $module_support_type;
  124. }
  125. function module_entries($name, $types = array(), $rid = 0, $args = null) {
  126. load()->func('communication');
  127. global $_W;
  128. $ts = array('rule', 'cover', 'menu', 'home', 'profile', 'shortcut', 'function', 'mine', 'system_welcome');
  129. if(empty($types)) {
  130. $types = $ts;
  131. } else {
  132. $types = array_intersect($types, $ts);
  133. }
  134. $bindings = pdo_getall('modules_bindings', array('module' => $name, 'entry' => $types), array(), '', 'displayorder DESC, multilevel DESC, eid ASC');
  135. $entries = array();
  136. $cache_key = cache_system_key('module_entry_call', array('module_name' => $name));
  137. $entry_call = cache_load($cache_key);
  138. if (empty($entry_call)) {
  139. $entry_call = array();
  140. }
  141. foreach($bindings as $bind) {
  142. if(!empty($bind['call'])) {
  143. if (empty($entry_call[$bind['entry']])) {
  144. $call_url = url('utility/bindcall', array('modulename' => $bind['module'], 'callname' => $bind['call'], 'args' => $args, 'uniacid' => $_W['uniacid']));
  145. $response = ihttp_request($call_url);
  146. if (is_error($response) || $response['code'] != 200) {
  147. $response = ihttp_request($_W['siteroot'] . 'web/' . $call_url); if (is_error($response) || $response['code'] != 200) {
  148. continue;
  149. }
  150. }
  151. $response = json_decode($response['content'], true);
  152. $ret = $response['message']['message'];
  153. if(is_array($ret)) {
  154. foreach($ret as $i => $et) {
  155. if (empty($et['url'])) {
  156. continue;
  157. }
  158. $urlinfo = url_params($et['url']);
  159. $et['do'] = empty($et['do']) ? $urlinfo['do'] : $et['do'];
  160. $et['url'] = $et['url'] . '&__title=' . urlencode($et['title']);
  161. $entry_call[$bind['entry']][] = array('eid' => 'user_' . $i, 'title' => $et['title'], 'do' => $et['do'], 'url' => $et['url'], 'from' => 'call', 'icon' => $et['icon'], 'displayorder' => $et['displayorder']);
  162. }
  163. }
  164. cache_write($cache_key, $entry_call, 300);
  165. }
  166. $entries[$bind['entry']] = $entry_call[$bind['entry']];
  167. } else {
  168. if (in_array($bind['entry'], array('cover', 'home', 'profile', 'shortcut'))) {
  169. $url = murl('entry', array('eid' => $bind['eid']));
  170. }
  171. if (in_array($bind['entry'], array('menu', 'system_welcome'))) {
  172. $url = wurl("site/entry", array('eid' => $bind['eid']));
  173. }
  174. if($bind['entry'] == 'mine') {
  175. $url = $bind['url'];
  176. }
  177. if($bind['entry'] == 'rule') {
  178. $par = array('eid' => $bind['eid']);
  179. if (!empty($rid)) {
  180. $par['id'] = $rid;
  181. }
  182. $url = wurl("site/entry", $par);
  183. }
  184. if(empty($bind['icon'])) {
  185. $bind['icon'] = 'wi wi-appsetting';
  186. }
  187. if (!defined('SYSTEM_WELCOME_MODULE') && $bind['entry'] == 'system_welcome') {
  188. continue;
  189. }
  190. $entries[$bind['entry']][] = array(
  191. 'eid' => $bind['eid'],
  192. 'title' => $bind['title'],
  193. 'do' => $bind['do'],
  194. 'url' => !$bind['multilevel'] ? $url : '',
  195. 'from' => 'define',
  196. 'icon' => $bind['icon'],
  197. 'displayorder' => $bind['displayorder'],
  198. 'direct' => $bind['direct'],
  199. 'multilevel' => $bind['multilevel'],
  200. 'parent' => $bind['parent'],
  201. );
  202. }
  203. }
  204. return $entries;
  205. }
  206. function module_app_entries($name, $types = array(), $args = null) {
  207. global $_W;
  208. $ts = array('rule', 'cover', 'menu', 'home', 'profile', 'shortcut', 'function');
  209. if(empty($types)) {
  210. $types = $ts;
  211. } else {
  212. $types = array_intersect($types, $ts);
  213. }
  214. $bindings = pdo_getall('modules_bindings', array('module' => $name, 'entry' => $types));
  215. $entries = array();
  216. foreach($bindings as $bind) {
  217. if(!empty($bind['call'])) {
  218. $extra = array();
  219. $extra['Host'] = $_SERVER['HTTP_HOST'];
  220. load()->func('communication');
  221. $urlset = parse_url($_W['siteurl']);
  222. $urlset = pathinfo($urlset['path']);
  223. $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);
  224. if (is_error($response)) {
  225. continue;
  226. }
  227. $response = json_decode($response['content'], true);
  228. $ret = $response['message']['message'];
  229. if(is_array($ret)) {
  230. foreach($ret as $et) {
  231. $et['url'] = $et['url'] . '&__title=' . urlencode($et['title']);
  232. $entries[$bind['entry']][] = array('title' => $et['title'], 'url' => $et['url'], 'from' => 'call');
  233. }
  234. }
  235. } else {
  236. if($bind['entry'] == 'cover') {
  237. $url = murl("entry", array('eid' => $bind['eid']));
  238. }
  239. if($bind['entry'] == 'home') {
  240. $url = murl("entry", array('eid' => $bind['eid']));
  241. }
  242. if($bind['entry'] == 'profile') {
  243. $url = murl("entry", array('eid' => $bind['eid']));
  244. }
  245. if($bind['entry'] == 'shortcut') {
  246. $url = murl("entry", array('eid' => $bind['eid']));
  247. }
  248. $entries[$bind['entry']][] = array('title' => $bind['title'], 'do' => $bind['do'], 'url' => $url, 'from' => 'define');
  249. }
  250. }
  251. return $entries;
  252. }
  253. function module_entry($eid) {
  254. $sql = "SELECT * FROM " . tablename('modules_bindings') . " WHERE `eid`=:eid";
  255. $pars = array();
  256. $pars[':eid'] = $eid;
  257. $entry = pdo_fetch($sql, $pars);
  258. if(empty($entry)) {
  259. return error(1, '模块菜单不存在');
  260. }
  261. $module = module_fetch($entry['module']);
  262. if(empty($module)) {
  263. return error(2, '模块不存在');
  264. }
  265. $querystring = array(
  266. 'do' => $entry['do'],
  267. 'm' => $entry['module'],
  268. );
  269. if (!empty($entry['state'])) {
  270. $querystring['state'] = $entry['state'];
  271. }
  272. $entry['url'] = murl('entry', $querystring);
  273. $entry['url_show'] = murl('entry', $querystring, true, true);
  274. return $entry;
  275. }
  276. function module_build_form($name, $rid, $option = array()) {
  277. $rid = intval($rid);
  278. $m = WeUtility::createModule($name);
  279. if(!empty($m)) {
  280. return $m->fieldsFormDisplay($rid, $option);
  281. }else {
  282. return null;
  283. }
  284. }
  285. function module_save_group_package($package) {
  286. global $_W;
  287. load()->model('user');
  288. load()->model('cache');
  289. if (empty($package['name'])) {
  290. return error(-1, '请输入套餐名');
  291. }
  292. if (!empty($package['modules'])) {
  293. $package['modules'] = iserializer($package['modules']);
  294. }
  295. if (!empty($package['templates'])) {
  296. $templates = array();
  297. foreach ($package['templates'] as $template) {
  298. $templates[] = $template['id'];
  299. }
  300. $package['templates'] = iserializer($templates);
  301. }
  302. if (!empty($package['id'])) {
  303. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'id <>' => $package['id'], 'name' => $package['name']));
  304. } else {
  305. $name_exist = pdo_get('uni_group', array('uniacid' => 0, 'name' => $package['name']));
  306. }
  307. if (!empty($name_exist)) {
  308. return error(-1, '套餐名已存在');
  309. }
  310. if (!empty($package['id'])) {
  311. pdo_update('uni_group', $package, array('id' => $package['id']));
  312. cache_build_account_modules();
  313. } else {
  314. pdo_insert('uni_group', $package);
  315. $uni_group_id = pdo_insertid();
  316. if (user_is_vice_founder()) {
  317. $table = table('users_founder_own_uni_groups');
  318. $table->addOwnUniGroup($_W['uid'], $uni_group_id);
  319. }
  320. }
  321. cache_build_uni_group();
  322. return error(0, '添加成功');
  323. }
  324. function module_fetch($name, $enabled = true) {
  325. global $_W;
  326. $cachekey = cache_system_key('module_info', array('module_name' => $name));
  327. $module = cache_load($cachekey);
  328. if (empty($module)) {
  329. $module_info = table('modules')->getByName($name);
  330. if (empty($module_info)) {
  331. return array();
  332. }
  333. if (!empty($module_info['subscribes'])) {
  334. $module_info['subscribes'] = (array)unserialize ($module_info['subscribes']);
  335. }
  336. if (!empty($module_info['handles'])) {
  337. $module_info['handles'] = (array)unserialize ($module_info['handles']);
  338. }
  339. $module_info['isdisplay'] = 1;
  340. $module_info['logo'] = tomedia($module_info['logo']);
  341. if (file_exists(IA_ROOT . '/addons/' . $module_info['name'] . '/preview-custom.jpg')) {
  342. $module_info['preview'] = tomedia(IA_ROOT . '/addons/' . $module_info['name'] . '/preview-custom.jpg', '', true);
  343. } else {
  344. $module_info['preview'] = tomedia(IA_ROOT . '/addons/' . $module_info['name'] . '/preview.jpg', '', true);
  345. }
  346. $module_info['main_module'] = pdo_getcolumn ('modules_plugin', array ('name' => $module_info['name']), 'main_module');
  347. if (!empty($module_info['main_module'])) {
  348. $main_module_info = module_fetch ($module_info['main_module']);
  349. $module_info['main_module_logo'] = $main_module_info['logo'];
  350. $module_info['main_module_title'] = $main_module_info['title'];
  351. } else {
  352. $module_info['plugin_list'] = pdo_getall ('modules_plugin', array ('main_module' => $module_info['name']), array (), 'name');
  353. if (!empty($module_info['plugin_list'])) {
  354. $module_info['plugin_list'] = array_keys ($module_info['plugin_list']);
  355. }
  356. }
  357. $module_receive_ban = (array)setting_load('module_receive_ban');
  358. if (is_array($module_receive_ban['module_receive_ban']) && in_array($name, $module_receive_ban['module_receive_ban'])) {
  359. $module_info['is_receive_ban'] = true;
  360. }
  361. $module_ban = (array)setting_load('module_ban');
  362. if (is_array($module_ban['module_ban']) && in_array($name, $module_ban['module_ban'])) {
  363. $module_info['is_ban'] = true;
  364. }
  365. $module_upgrade = (array)setting_load('module_upgrade');
  366. if (is_array($module_upgrade['module_upgrade']) && in_array($name, array_keys($module_upgrade['module_upgrade']))) {
  367. $module_info['is_upgrade'] = true;
  368. }
  369. $module_info['recycle_info'] = array();
  370. $recycle_info = table('modules_recycle')->getByName($name);
  371. if (!empty($recycle_info)) {
  372. $is_delete = true;
  373. foreach (module_support_type() as $support => $value) {
  374. if (!empty($recycle_info[MODULE_RECYCLE_UNINSTALL_IGNORE][$support])) {
  375. $module_info['recycle_info'][$support] = MODULE_RECYCLE_UNINSTALL_IGNORE; } else {
  376. $module_info['recycle_info'][$support] = empty($recycle_info[MODULE_RECYCLE_INSTALL_DISABLED][$support]) ? 0 : MODULE_RECYCLE_INSTALL_DISABLED;
  377. }
  378. if ($module_info[$support] == $value['support'] && empty($module_info['recycle_info'][$support])) {
  379. $is_delete = false;
  380. }
  381. }
  382. $module_info['is_delete'] = $is_delete; }
  383. $module = $module_info;
  384. cache_write($cachekey, $module_info);
  385. }
  386. if (!empty($enabled)) {
  387. if (!empty($module['is_delete'])) {
  388. return array();
  389. }
  390. }
  391. if (!empty($module) && !empty($_W['uniacid'])) {
  392. $setting_cachekey = cache_system_key('module_setting', array('module_name' => $name, 'uniacid' => $_W['uniacid']));
  393. $setting = cache_load($setting_cachekey);
  394. if (empty($setting)) {
  395. $setting = pdo_get('uni_account_modules', array('module' => $name, 'uniacid' => $_W['uniacid']));
  396. $setting = empty($setting) ? array('module' => $name) : $setting;
  397. cache_write($setting_cachekey, $setting);
  398. }
  399. $module['config'] = !empty($setting['settings']) ? iunserializer($setting['settings']) : array();
  400. $module['enabled'] = $module['issystem'] || !isset($setting['enabled']) ? 1 : $setting['enabled'];
  401. $module['displayorder'] = $setting['displayorder'];
  402. $module['shortcut'] = $setting['shortcut'];
  403. $module['module_shortcut'] = $setting['module_shortcut'];
  404. }
  405. return $module;
  406. }
  407. function module_permission_fetch($name) {
  408. $module = module_fetch($name);
  409. $data = array();
  410. if($module['settings']) {
  411. $data[] = array('title' => '参数设置', 'permission' => $name.'_settings');
  412. }
  413. if($module['isrulefields']) {
  414. $data[] = array('title' => '回复规则列表', 'permission' => $name.'_rule');
  415. }
  416. $entries = module_entries($name);
  417. if(!empty($entries['home'])) {
  418. $data[] = array('title' => '微站首页导航', 'permission' => $name.'_home');
  419. }
  420. if(!empty($entries['profile'])) {
  421. $data[] = array('title' => '个人中心导航', 'permission' => $name.'_profile');
  422. }
  423. if(!empty($entries['shortcut'])) {
  424. $data[] = array('title' => '快捷菜单', 'permission' => $name.'_shortcut');
  425. }
  426. if(!empty($entries['cover'])) {
  427. foreach($entries['cover'] as $cover) {
  428. $data[] = array('title' => $cover['title'], 'permission' => $name.'_cover_'.$cover['do']);
  429. }
  430. }
  431. if(!empty($entries['menu'])) {
  432. foreach($entries['menu'] as $menu) {
  433. $data[$menu['do']] = array('title' => $menu['title'], 'permission' => $name.'_menu_'.$menu['do']);
  434. }
  435. }
  436. unset($entries);
  437. if(!empty($module['permissions'])) {
  438. $module['permissions'] = (array)iunserializer($module['permissions']);
  439. foreach ($module['permissions'] as $permission) {
  440. if (!empty($permission['parent']) && !empty($data[$permission['parent']])) {
  441. $sub_permission = array(
  442. 'title' => $permission['title'],
  443. 'permission' => $name . '_menu_' . $permission['parent'] . '_' . $permission['permission'],
  444. );
  445. if (empty($data[$permission['parent']]['sub_permission'])) {
  446. $data[$permission['parent']]['sub_permission'] = array($sub_permission);
  447. } else {
  448. array_push($data[$permission['parent']]['sub_permission'], $sub_permission);
  449. }
  450. }
  451. $data[] = array('title' => $permission['title'], 'permission' => $name . '_permission_' . $permission['permission']);
  452. }
  453. }
  454. return $data;
  455. }
  456. function module_get_plugin_list($module_name) {
  457. $module_info = module_fetch($module_name);
  458. if (!empty($module_info['plugin_list']) && is_array($module_info['plugin_list'])) {
  459. $plugin_list = array();
  460. foreach ($module_info['plugin_list'] as $plugin) {
  461. $plugin_info = module_fetch($plugin);
  462. if (!empty($plugin_info)) {
  463. $plugin_list[$plugin] = $plugin_info;
  464. }
  465. }
  466. return $plugin_list;
  467. } else {
  468. return array();
  469. }
  470. }
  471. function module_status($module) {
  472. load()->model('cloud');
  473. $result = array(
  474. 'upgrade' => array(
  475. 'has_upgrade' => false,
  476. ),
  477. 'ban' => false,
  478. );
  479. $module_cloud_info = table('modules_cloud')->getByName($module);
  480. if (!empty($module_cloud_info['has_new_version']) || !empty($module_cloud_info['has_new_branch'])) {
  481. $result['upgrade'] = array(
  482. 'has_upgrade' => true,
  483. 'name' => $module_cloud_info['title'],
  484. 'version' => $module_cloud_info['version'],
  485. );
  486. }
  487. if (!empty($module_cloud_info['is_ban'])) {
  488. $result['ban'] = true;
  489. }
  490. return $result;
  491. }
  492. function module_exist_in_account($module_name, $uniacid) {
  493. global $_W;
  494. $result = false;
  495. $module_name = trim($module_name);
  496. $uniacid = intval($uniacid);
  497. if (empty($module_name) || empty($uniacid)) {
  498. return $result;
  499. }
  500. $founders = explode(',', $_W['config']['setting']['founder']);
  501. $owner_uid = pdo_getcolumn('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'), 'uid');
  502. if (!empty($owner_uid) && !in_array($owner_uid, $founders)) {
  503. if (IMS_FAMILY == 'x') {
  504. $account_info = uni_fetch($uniacid);
  505. if (in_array($account_info['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH))) {
  506. $site_store_buy_goods = uni_site_store_buy_goods($uniacid, STORE_TYPE_WXAPP_MODULE);
  507. } else {
  508. $site_store_buy_goods = uni_site_store_buy_goods($uniacid);
  509. }
  510. } else {
  511. $site_store_buy_goods = array();
  512. }
  513. $account_table = table('account');
  514. $uni_modules = $account_table->accountGroupModules($uniacid);
  515. $user_modules = user_modules($owner_uid);
  516. $modules = array_merge(array_keys($user_modules), $uni_modules, $site_store_buy_goods);
  517. $result = in_array($module_name, $modules) ? true : false;
  518. } else {
  519. $result = true;
  520. }
  521. return $result;
  522. }
  523. function module_get_user_account_list($uid, $module_name) {
  524. $accounts_list = array();
  525. $uid = intval($uid);
  526. $module_name = trim($module_name);
  527. if (empty($uid) || empty($module_name)) {
  528. return $accounts_list;
  529. }
  530. $module_info = module_fetch($module_name);
  531. if (empty($module_info)) {
  532. return $accounts_list;
  533. }
  534. $account_users_info = table('account')->userOwnedAccount($uid);
  535. if (empty($account_users_info)) {
  536. return $accounts_list;
  537. }
  538. $accounts = array();
  539. foreach ($account_users_info as $account) {
  540. if (empty($account['uniacid'])) {
  541. continue;
  542. }
  543. $uniacid = 0;
  544. if (($account['type'] == ACCOUNT_TYPE_OFFCIAL_NORMAL || $account['type'] == ACCOUNT_TYPE_OFFCIAL_AUTH) && $module_info[MODULE_SUPPORT_ACCOUNT_NAME] == MODULE_SUPPORT_ACCOUNT) {
  545. $uniacid = $account['uniacid'];
  546. } elseif ($account['type'] == ACCOUNT_TYPE_APP_NORMAL && $module_info['wxapp_support'] == MODULE_SUPPORT_WXAPP) {
  547. $uniacid = $account['uniacid'];
  548. } elseif (($account['type'] == ACCOUNT_TYPE_XZAPP_NORMAL || $account['type'] == ACCOUNT_TYPE_XZAPP_AUTH) && $module_info[MODULE_SUPPORT_XZAPP_NAME] == MODULE_SUPPORT_XZAPP) {
  549. $uniacid = $account['uniacid'];
  550. } elseif (($account['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL && $module_info[MODULE_SUPPORT_WEBAPP_NAME] == MODULE_SUPPORT_WEBAPP)) {
  551. $uniacid = $account['uniacid'];
  552. } elseif (($account['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL && $module_info[MODULE_SUPPORT_PHONEAPP_NAME] == MODULE_SUPPORT_PHONEAPP)) {
  553. $uniacid = $account['uniacid'];
  554. } elseif (($account['type'] == ACCOUNT_TYPE_ALIAPP_NORMAL && $module_info[MODULE_SUPPORT_ALIAPP_NAME] == MODULE_SUPPORT_ALIAPP)) {
  555. $uniacid = $account['uniacid'];
  556. }
  557. if (!empty($uniacid)) {
  558. if (module_exist_in_account($module_name, $uniacid)) {
  559. $accounts_list[$uniacid] = $account;
  560. }
  561. }
  562. }
  563. return $accounts_list;
  564. }
  565. function module_link_uniacid_fetch($uid, $module_name) {
  566. load()->model('phoneapp');
  567. $result = array();
  568. $uid = intval($uid);
  569. $module_name = trim($module_name);
  570. if (empty($uid) || empty($module_name)) {
  571. return $result;
  572. }
  573. $accounts_list = module_get_user_account_list($uid, $module_name);
  574. if (empty($accounts_list)) {
  575. return $result;
  576. }
  577. $accounts_link_result = array();
  578. foreach ($accounts_list as $key => $account_value) {
  579. $account_info = uni_fetch($account_value['uniacid']);
  580. if ($account_info->supportVersion) {
  581. if ($account_value['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  582. $account_value['versions'] = phoneapp_version_all($account_value['uniacid']);
  583. } else {
  584. $account_value['versions'] = miniapp_version_all($account_value['uniacid']);
  585. }
  586. if (empty($account_value['versions'])) {
  587. $accounts_link_result[$key] = $account_value;
  588. continue;
  589. }
  590. foreach ($account_value['versions'] as $version_key => $version_value) {
  591. if (empty($version_value['modules'])) {
  592. continue;
  593. }
  594. $version_module_names = array_column($version_value['modules'], 'name');
  595. if (!in_array($module_name, $version_module_names)) {
  596. continue;
  597. }
  598. if (empty($version_value['modules'][0]['account']) || !is_array($version_value['modules'][0]['account'])) {
  599. $accounts_link_result[$key] = $account_value;
  600. continue;
  601. }
  602. if (!empty($version_value['modules'][0]['account']['uniacid'])) {
  603. $accounts_link_result[$version_value['modules'][0]['account']['uniacid']][] = array(
  604. 'uniacid' => $key,
  605. 'version' => $version_value['version'],
  606. 'version_id' => $version_value['id'],
  607. 'name' => $account_value['name'],
  608. );
  609. unset($account_value['versions'][$version_key]);
  610. }
  611. }
  612. } 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) {
  613. if (empty($accounts_link_result[$key])) {
  614. $accounts_link_result[$key] = $account_value;
  615. } else {
  616. $link_wxapp = $accounts_link_result[$key];
  617. $accounts_link_result[$key] = $account_value;
  618. $accounts_link_result[$key]['link_wxapp'] = $link_wxapp;
  619. }
  620. } else {
  621. if (empty($accounts_link_result[$key])) {
  622. $accounts_link_result[$key] = $account_value;
  623. }
  624. }
  625. }
  626. if (!empty($accounts_link_result)) {
  627. foreach ($accounts_link_result as $link_key => $link_value) {
  628. if (in_array($link_value['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  629. $link_value['type_name'] = ACCOUNT_TYPE_SIGN;
  630. } elseif (in_array($link_value['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH))) {
  631. $link_value['type_name'] = WXAPP_TYPE_SIGN;
  632. } elseif ($link_value['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  633. $link_value['type_name'] = WEBAPP_TYPE_SIGN;
  634. }elseif ($link_value['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  635. $link_value['type_name'] = PHONEAPP_TYPE_SIGN;
  636. }elseif ($link_value['type'] == ACCOUNT_TYPE_XZAPP_NORMAL) {
  637. $link_value['type_name'] = XZAPP_TYPE_SIGN;
  638. }elseif ($link_value['type'] == ACCOUNT_TYPE_ALIAPP_NORMAL) {
  639. $link_value['type_name'] = ALIAPP_TYPE_SIGN;
  640. }
  641. 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'])) {
  642. foreach ($link_value['link_wxapp'] as $value) {
  643. $result[] = array(
  644. 'app_name' => $link_value['name'],
  645. 'wxapp_name' => $value['name'] . ' ' . $value['version'],
  646. 'uniacid' => $link_value['uniacid'],
  647. 'version_id' => $value['version_id'],
  648. 'type_name' => $link_value['type_name'],
  649. 'account_name' => $link_value['name'],
  650. 'type' => $link_value['type'],
  651. 'logo' => to_global_media('headimg_' . $link_value['acid'] . '.jpg') . '?time=' . time(),
  652. );
  653. }
  654. } elseif ($link_value['type'] == ACCOUNT_TYPE_APP_NORMAL && !empty($link_value['versions']) && is_array($link_value['versions'])) {
  655. foreach ($link_value['versions'] as $value) {
  656. $result[] = array(
  657. 'app_name' => '',
  658. 'wxapp_name' => $link_value['name'] . ' ' . $value['version'],
  659. 'uniacid' => $link_value['uniacid'],
  660. 'version_id' => $value['id'],
  661. 'type_name' => $link_value['type_name'],
  662. 'account_name' => $link_value['name'],
  663. 'type' => $link_value['type'],
  664. 'logo' => to_global_media('headimg_' . $link_value['acid'] . '.jpg') . '?time=' . time(),
  665. );
  666. }
  667. } else {
  668. $result[] = array(
  669. 'app_name' => $link_value['name'],
  670. 'wxapp_name' => '',
  671. 'uniacid' => $link_value['uniacid'],
  672. 'version_id' => '',
  673. 'type_name' => $link_value['type_name'],
  674. 'account_name' => $link_value['name'],
  675. 'type' => $link_value['type'],
  676. 'logo' => to_global_media('headimg_' . $link_value['acid'] . '.jpg') . '?time=' . time(),
  677. );
  678. }
  679. }
  680. }
  681. return $result;
  682. }
  683. function module_clerk_info($module_name) {
  684. $user_permissions = array();
  685. $module_name = trim($module_name);
  686. if (empty($module_name)) {
  687. return $user_permissions;
  688. }
  689. $user_permissions = table('users_permission')->getClerkPermission($module_name);
  690. if (!empty($user_permissions)) {
  691. foreach ($user_permissions as $key => $value) {
  692. $user_permissions[$key]['user_info'] = user_single($value['uid']);
  693. }
  694. }
  695. return $user_permissions;
  696. }
  697. function module_rank_top($module_name, $uniacid) {
  698. global $_W;
  699. if (empty($module_name)) {
  700. return false;
  701. }
  702. $result = table('modules_rank')->setTop($module_name, $uniacid);
  703. return empty($result) ? true : false;
  704. }
  705. function module_installed_list($type = '') {
  706. global $_W;
  707. $module_list = array();
  708. $user_has_module = user_modules($_W['uid']);
  709. if (empty($user_has_module)) {
  710. return $module_list;
  711. }
  712. if ($type == 'all') {
  713. return $user_has_module;
  714. }
  715. foreach ($user_has_module as $modulename => $module) {
  716. if ((!empty($module['issystem']) && $module['name'] != 'we7_coupon')) {
  717. continue;
  718. }
  719. foreach (module_support_type() as $support_name => $support) {
  720. if ($module[$support_name] == $support['support'] && (empty($module['recycle_info']) || empty($module['recycle_info'][$support_name]))) {
  721. $module_list[$support['type']][$modulename] = $module;
  722. }
  723. }
  724. }
  725. if (!empty($type)) {
  726. return (array)$module_list[$type];
  727. } else {
  728. return $module_list;
  729. }
  730. }
  731. function module_uninstall_list() {
  732. $uninstall_modules = table('modules_cloud')->getUninstallModule();
  733. $recycle = table('modules_recycle')->where('type', 2)->where('name', array_keys($uninstall_modules))->getall('name');
  734. if (!empty($uninstall_modules)) {
  735. foreach ($uninstall_modules as $name => &$module) {
  736. if (!empty($recycle[$name])) {
  737. foreach (module_support_type() as $support => $value) {
  738. if ($module[$support] == $value['support'] && $recycle[$name][$support] == 1) {
  739. $module[$support] = $value['not_support'];
  740. }
  741. }
  742. }
  743. $need_install = false;
  744. foreach (module_support_type() as $support => $value) {
  745. if ($module[$support] == MODULE_SUPPORT_ACCOUNT) {
  746. $need_install = true;
  747. $module['link'] = url('module/manage-system/install', array('module_name' => $module['name'], 'support' => $support));
  748. break;
  749. }
  750. }
  751. if (!$need_install) {
  752. unset($module);
  753. }
  754. }
  755. }
  756. return $uninstall_modules;
  757. }
  758. function module_uninstall_total($type) {
  759. $type_list = module_support_type();
  760. if (!isset($type_list["{$type}_support"]) && $type != 'all') {
  761. return 0;
  762. }
  763. if ($type == 'all') {
  764. $total = table('modules_cloud')->searchUninstallWithOutWelcome()->getcolumn('count(*)');
  765. } else {
  766. $total = table('modules_cloud')->searchUninstallSupport("{$type}_support")->getcolumn('count(*)');
  767. }
  768. return intval($total);
  769. }
  770. function module_upgrade_list() {
  771. global $_W;
  772. $result = array();
  773. $module_list = user_modules($_W['uid']);
  774. if (empty($module_list)) {
  775. return $result;
  776. }
  777. $modules_cloud_table = table('modules_cloud');
  778. $modules_cloud_table->orderby('buytime', 'desc');
  779. $modules_cloud_table->orderby('lastupdatetime', 'asc');
  780. $upgrade_modules = $modules_cloud_table->getUpgradeByModuleNameList(array_keys($module_list));
  781. if (empty($upgrade_modules)) {
  782. return $result;
  783. }
  784. $modules_ignore = table('modules_ignore')->where('name', array_keys($upgrade_modules))->getall('name');
  785. foreach ($upgrade_modules as $modulename => &$module) {
  786. if (!empty($modules_ignore[$modulename])) {
  787. if (ver_compare($modules_ignore[$modulename]['version'], $module['version']) >= 0) {
  788. $module['is_ignore'] = 1;
  789. }
  790. }
  791. $module['link'] = url('module/manage-system/module_detail', array('name' => $module['name'], 'show' => 'upgrade'));
  792. }
  793. unset($module);
  794. return $upgrade_modules;
  795. }
  796. function module_upgrade_total($type) {
  797. $type_list = module_support_type();
  798. if (!isset($type_list["{$type}_support"])) {
  799. return 0;
  800. }
  801. $modules = table('modules_cloud')->getUpgradeModulesBySupportType($type);
  802. return count($modules);
  803. }
  804. function module_upgrade_info($modulelist = array()) {
  805. load()->model('cloud');
  806. load()->model('extension');
  807. $result = array();
  808. cloud_prepare();
  809. $cloud_m_query_module = cloud_m_query();
  810. //qwj
  811. $module_support_type = module_support_type();
  812. if (!empty($cloud_m_query_module) && !is_error($cloud_m_query_module)) {
  813. //return array();
  814. $pirate_apps = $cloud_m_query_module['pirate_apps'];
  815. unset($cloud_m_query_module['pirate_apps']);
  816. $manifest_cloud_list = array();
  817. foreach ($cloud_m_query_module as $modulename => $manifest_cloud) {
  818. $manifest = array(
  819. 'application' => array(
  820. 'name' => $modulename,
  821. 'title' => $manifest_cloud['title'],
  822. 'version' => $manifest_cloud['version'],
  823. 'logo' => $manifest_cloud['thumb'],
  824. 'last_upgrade_time' => $manifest_cloud['last_upgrade_time'],
  825. ),
  826. 'platform' => array(
  827. 'supports' => array()
  828. ),
  829. );
  830. foreach ($module_support_type as $support_key => $support_value) {
  831. if ($support_key == 'account_support' && $manifest_cloud['site_branch']['app_support'] == $support_value['support']) {
  832. $manifest['platform']['supports'][] = $support_value['type'];
  833. continue;
  834. }
  835. if ($support_key == 'phoneapp_support' && ($manifest_cloud['site_branch']['android_support'] == $support_value['support'] || $manifest_cloud['site_branch']['ios_support'] == $support_value['support'])) {
  836. $manifest['platform']['supports'][] = $support_value['type'];
  837. continue;
  838. }
  839. if ($support_key == 'welcome_support' && $manifest_cloud['site_branch']['system_welcome_support'] == $support_value['support']) {
  840. $manifest['platform']['supports'][] = $support_value['type'];
  841. continue;
  842. }
  843. if ($manifest_cloud['site_branch'][$support_key] == $support_value['support']) {
  844. $manifest['platform']['supports'][] = $support_value['type'];
  845. }
  846. }
  847. if (empty($manifest['platform']['supports'])) {
  848. continue;
  849. }
  850. $manifest['branches'] = $manifest_cloud['branches'];
  851. $manifest['site_branch'] = $manifest_cloud['site_branch'];
  852. $manifest['cloud_id'] = $manifest_cloud['id'];
  853. $manifest['buytime'] = $manifest_cloud['buytime'];
  854. $manifest_cloud_list[$modulename] = $manifest;
  855. }
  856. }
  857. if (empty($modulelist)) {
  858. $modulelist = table('modules')->searchWithType('system', '<>')->getall('name');
  859. }
  860. foreach ($modulelist as $modulename => $module) {
  861. if (!empty($module['issystem'])) {
  862. unset($modulelist[$modulename]);
  863. continue;
  864. }
  865. $module_upgrade_data = array(
  866. 'name' => $modulename,
  867. 'has_new_version' => 0,
  868. 'has_new_branch' => 0,
  869. );
  870. if (!empty($pirate_apps) && in_array($modulename, $pirate_apps)) {
  871. $module_upgrade_data['is_ban'] = 1;
  872. }
  873. $manifest = ext_module_manifest($modulename);
  874. if (!empty($manifest)) {
  875. $module_upgrade_data['install_status'] = MODULE_LOCAL_INSTALL;
  876. } elseif ($manifest_cloud_list[$modulename]) {
  877. $module_upgrade_data['install_status'] = MODULE_CLOUD_INSTALL;
  878. $manifest = $manifest_cloud_list[$modulename];
  879. } else {
  880. $module_upgrade_data['install_status'] = MODULE_LOCAL_INSTALL;
  881. }
  882. $module_upgrade_data['logo'] = $manifest['application']['logo'];
  883. $module_upgrade_data['version'] = $manifest['application']['version'];
  884. $module_upgrade_data['title'] = $manifest['application']['title'];
  885. $module_upgrade_data['title_initial'] = get_first_pinyin($manifest['application']['title']);
  886. $module_upgrade_data['buytime'] = $manifest_cloud_list[$modulename]['buytime'];
  887. unset($manifest_cloud_list[$modulename]);
  888. if (version_compare($module['version'], $manifest['application']['version']) == '-1') {
  889. $module_upgrade_data['has_new_version'] = 1;
  890. $module_upgrade_data['lastupdatetime'] = TIMESTAMP;
  891. $result[$modulename] = array(
  892. 'name' => $modulename,
  893. 'new_version' => 1,
  894. 'best_version' => $manifest['application']['version'],
  895. );
  896. }
  897. if ($module_upgrade_data['install_status'] == MODULE_LOCAL_INSTALL && empty($module_upgrade_data['has_new_version'])) {
  898. continue;
  899. }
  900. if (!empty($manifest['branches'])) {
  901. foreach ($manifest['branches'] as &$branch) {
  902. if ($branch['displayorder'] > $manifest['site_branch']['displayorder'] || ($branch['displayorder'] == $manifest['site_branch']['displayorder'] && $manifest['site_branch']['id'] < intval($branch['id']))) {
  903. $module_upgrade_data['has_new_branch'] = 1;
  904. $result[$modulename]['new_branch'] = 1;
  905. }
  906. }
  907. }
  908. if (!empty($manifest['platform']['supports'])) {
  909. foreach (array('app', 'wxapp', 'webapp', 'android', 'ios', 'system_welcome', 'xzapp', 'aliapp', 'baiduapp', 'toutiaoapp') as $support) {
  910. if (in_array($support, $manifest['platform']['supports'])) {
  911. if ($support == 'app') {
  912. $support = 'account';
  913. }
  914. if ($support == 'system_welcome') {
  915. $support = 'welcome';
  916. }
  917. if ($support == 'android' || $support == 'ios') {
  918. $support = 'phoneapp';
  919. }
  920. $module_upgrade_data["{$support}_support"] = MODULE_SUPPORT_ACCOUNT;
  921. }else{
  922. if ($support == 'app') {
  923. $support = 'account';
  924. }
  925. if ($support == 'system_welcome') {
  926. $support = 'welcome';
  927. }
  928. if ($support == 'android' || $support == 'ios') {
  929. $support = 'phoneapp';
  930. }
  931. $module_upgrade_data["{$support}_support"] = MODULE_NONSUPPORT_ACCOUNT;
  932. }
  933. }
  934. /* qwj
  935. foreach ($module_support_type as $support_key => $support_value) {
  936. if (in_array($support_value['type'], $manifest['platform']['supports'])) {
  937. $module_upgrade_data[$support_key] = $support_value['support'];
  938. } else {
  939. $module_upgrade_data[$support_key] = $support_value['not_support'];
  940. }
  941. } */
  942. }
  943. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  944. if (empty($module_cloud_upgrade)) {
  945. pdo_insert('modules_cloud', $module_upgrade_data);
  946. } else {
  947. pdo_update('modules_cloud', $module_upgrade_data, array('name' => $modulename));
  948. }
  949. }
  950. if (!empty($manifest_cloud_list)) {
  951. foreach ($manifest_cloud_list as $modulename => $manifest) {
  952. $module_upgrade_data = array(
  953. 'name' => $modulename,
  954. 'has_new_version' => 0,
  955. 'has_new_branch' => 0,
  956. 'install_status' => MODULE_CLOUD_UNINSTALL,
  957. 'logo' => $manifest['application']['logo'],
  958. 'version' => $manifest['application']['version'],
  959. 'title' => $manifest['application']['title'],
  960. 'title_initial' => get_first_pinyin($manifest['application']['title']),
  961. 'lastupdatetime' => $manifest['application']['last_upgrade_time'],
  962. 'buytime' => $manifest['buytime'],
  963. 'cloud_id' => $manifest['cloud_id'],
  964. );
  965. if (!empty($manifest['platform']['supports'])) {
  966. foreach ($module_support_type as $support_key => $support_value) {
  967. if (in_array($support_value['type'], $manifest['platform']['supports'])) {
  968. $module_upgrade_data[$support_key] = $support_value['support'];
  969. } else {
  970. $module_upgrade_data[$support_key] = $support_value['not_support'];
  971. }
  972. }
  973. }
  974. $module_recycle_info = table('modules_recycle')->searchWithNameType($modulename, MODULE_RECYCLE_UNINSTALL_IGNORE)->get();
  975. if (!empty($module_recycle_info)) {
  976. foreach ($module_support_type as $support => $value) {
  977. if ($module_recycle_info[$support] == 1) {
  978. $module_upgrade_data[$support] = $value['not_support'];
  979. }
  980. }
  981. }
  982. $module_cloud_upgrade = table('modules_cloud')->getByName($modulename);
  983. if (empty($module_cloud_upgrade)) {
  984. pdo_insert('modules_cloud', $module_upgrade_data);
  985. } else {
  986. pdo_update('modules_cloud', $module_upgrade_data, array('name' => $modulename));
  987. }
  988. }
  989. }
  990. return $result;
  991. }
  992. function module_check_notinstalled_support($module, $manifest_support) {
  993. if (empty($manifest_support)) {
  994. return array();
  995. }
  996. $has_notinstalled_support = false;
  997. $notinstalled_support = array();
  998. $module_support_type = module_support_type();
  999. foreach ($manifest_support as $support) {
  1000. if ($support == 'app') {
  1001. $support = 'account';
  1002. } elseif ($support == 'system_welcome') {
  1003. $support = 'welcome';
  1004. } elseif ($support == 'android' || $support == 'ios') {
  1005. $support = 'phoneapp';
  1006. }
  1007. $support .= '_support';
  1008. if (!in_array($support, array_keys($module_support_type))) {
  1009. continue;
  1010. }
  1011. if ($module[$support] != $module_support_type[$support]['support']) {
  1012. $has_notinstalled_support = true;
  1013. $notinstalled_support[$support] = $module_support_type[$support]['support'];
  1014. } else {
  1015. $notinstalled_support[$support] = $module_support_type[$support]['not_support'];
  1016. }
  1017. }
  1018. if ($has_notinstalled_support) {
  1019. return $notinstalled_support;
  1020. } else {
  1021. return array();
  1022. }
  1023. }
  1024. function module_add_to_uni_group($module, $uni_group_id, $support) {
  1025. if (!in_array($support, array_keys(module_support_type()))) {
  1026. return error(1, '支持类型不存在');
  1027. }
  1028. if (empty($module[$support]) || $module[$support] != MODULE_SUPPORT_ACCOUNT) {
  1029. return error(1, '模块支持不存在');
  1030. }
  1031. $unigroup_table = table('uni_group');
  1032. $uni_group = $unigroup_table->getById($uni_group_id);
  1033. if (empty($uni_group)) {
  1034. return error(1, '应用权限组不存在');
  1035. }
  1036. $update_data = $uni_group['modules'];
  1037. $key = str_replace('_support', '', $support);
  1038. $key = $key == 'account' ? 'modules' : $key;
  1039. if (!in_array($module['name'], $update_data[$key])) {
  1040. $update_data[$key][] = $module['name'];
  1041. }
  1042. return $unigroup_table->fill('modules', iserializer($update_data))->where('id', $uni_group_id)->save();
  1043. }
  1044. function module_recycle($modulename, $type, $support) {
  1045. global $_W;
  1046. $module_support_types = module_support_type();
  1047. $module_support_type = $module_support_types[$support]['type'];
  1048. $all_support = array_keys($module_support_types);
  1049. if ($type == MODULE_RECYCLE_INSTALL_DISABLED) {
  1050. $uni_modules_table = table('uni_modules');
  1051. $uni_accounts = $uni_modules_table->where('module_name', $modulename)->getall('uniacid');
  1052. if (!empty($uni_accounts)) {
  1053. foreach ($uni_accounts as $uni_account_val) {
  1054. $account_info = uni_fetch($uni_account_val['uniacid']);
  1055. if ($account_info['type_sign'] == $module_support_type) {
  1056. $uni_modules_table->deleteUniModules($modulename, $uni_account_val['uniacid']);
  1057. }
  1058. }
  1059. }
  1060. $lastuse_table = table('users_lastuse');
  1061. $lastuse_accounts = switch_getall_lastuse_by_module($modulename);
  1062. if (!empty($lastuse_accounts)) {
  1063. foreach ($lastuse_accounts as $lastuse_account_val) {
  1064. $lastuse_account_info = uni_fetch($lastuse_account_val['uniacid']);
  1065. if ($lastuse_account_info['type_sign'] == $module_support_type) {
  1066. $lastuse_table->searchWithUid($_W['uid']);
  1067. $lastuse_table->searchWithUniacid($lastuse_account_val['uniacid']);
  1068. $lastuse_table->searchWithModule($modulename);
  1069. $lastuse_table->delete();
  1070. }
  1071. }
  1072. }
  1073. }
  1074. if (!in_array($support, $all_support)) {
  1075. return false;
  1076. }
  1077. if ($type == MODULE_RECYCLE_UNINSTALL_IGNORE) {
  1078. table('modules_cloud')->fill(array($support => 1))->where('name', $modulename)->save();
  1079. }
  1080. $module_recycle = table('modules_recycle');
  1081. $record = $module_recycle->searchWithNameType($modulename, $type)->get();
  1082. if (empty($record)) {
  1083. return $module_recycle->fill(array('name' => $modulename, 'type' => $type, $support => 1))->save();
  1084. } else {
  1085. $record[$support] = 1;
  1086. return $module_recycle->where('id', $record['id'])->fill($record)->save();
  1087. }
  1088. }
  1089. function module_cancel_recycle($modulename, $type, $support) {
  1090. $all_support = array_keys(module_support_type());
  1091. if (!in_array($support, $all_support)) {
  1092. return false;
  1093. }
  1094. $module_recycle = table('modules_recycle');
  1095. $record = $module_recycle->searchWithNameType($modulename, $type)->get();
  1096. if (empty($record)) {
  1097. return true;
  1098. }
  1099. $record[$support] = 0;
  1100. $is_update = false;
  1101. foreach ($all_support as $s) {
  1102. if ($record[$s] == 1) {
  1103. $is_update = true;
  1104. }
  1105. }
  1106. if ($type == MODULE_RECYCLE_UNINSTALL_IGNORE) {
  1107. table('modules_cloud')->fill(array($support => 2))->where('name', $modulename)->save();
  1108. }
  1109. if ($is_update) {
  1110. return $module_recycle->where('id', $record['id'])->fill($record)->save();
  1111. } else {
  1112. return $module_recycle->where('id', $record['id'])->delete();
  1113. }
  1114. }
  1115. function module_get_direct_enter_status($module_name) {
  1116. global $_W;
  1117. if (empty($module_name)) {
  1118. return STATUS_OFF;
  1119. }
  1120. $module_setting = table('uni_account_modules')->getByUniacidAndModule($module_name, $_W['uniacid']);
  1121. $status = !empty($module_setting['settings']) && $module_setting['settings']['direct_enter'] == STATUS_ON ? STATUS_ON : STATUS_OFF;
  1122. return $status;
  1123. }
  1124. function module_change_direct_enter_status($module_name) {
  1125. global $_W;
  1126. if (empty($module_name)) {
  1127. return false;
  1128. }
  1129. $module_setting = table('uni_account_modules')->getByUniacidAndModule($module_name, $_W['uniacid']);
  1130. $direct_enter_status = !empty($module_setting['settings']) && $module_setting['settings']['direct_enter'] == STATUS_ON ? STATUS_OFF : STATUS_ON;
  1131. if (empty($module_setting)) {
  1132. $data = array('direct_enter' => $direct_enter_status);
  1133. $result = table('uni_account_modules')->fill(array('settings' => iserializer($data), 'uniacid' => $_W['uniacid'], 'module' => $module_name))->save();
  1134. } else {
  1135. $module_setting['settings']['direct_enter'] = $direct_enter_status;
  1136. $data = $module_setting['settings'];
  1137. $result = table('uni_account_modules')->fill(array('settings' => iserializer($data)))->where('module', $module_name)->where('uniacid', $_W['uniacid'])->save();
  1138. }
  1139. return $result ? true : false;
  1140. }
  1141. function module_delete_store_wish_goods($module_name, $support_name) {
  1142. load()->model('store');
  1143. $all_type = store_goods_type_info();
  1144. foreach ($all_type as $info) {
  1145. if ($info['group'] == 'module' && $support_name == $info['sign'] . '_support') {
  1146. $type = $info['type'];
  1147. break;
  1148. }
  1149. }
  1150. if (!empty($type)) {
  1151. pdo_update('site_store_goods', array('status' => 2), array('module' => $module_name, 'type' => $type));
  1152. }
  1153. return true;
  1154. }