人人商城

extension.mod.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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 ext_module_convert($manifest) {
  8. if (!empty($manifest['platform']['supports'])) {
  9. $app_support = in_array('app', $manifest['platform']['supports']) ? MODULE_SUPPORT_ACCOUNT : MODULE_NONSUPPORT_ACCOUNT;
  10. $wxapp_support = in_array('wxapp', $manifest['platform']['supports']) ? MODULE_SUPPORT_WXAPP : MODULE_NONSUPPORT_WXAPP;
  11. $welcome_support = in_array('system_welcome', $manifest['platform']['supports']) ? MODULE_SUPPORT_SYSTEMWELCOME : MODULE_NONSUPPORT_SYSTEMWELCOME;
  12. $webapp_support = in_array('webapp', $manifest['platform']['supports']) ? MODULE_SUPPORT_WEBAPP : MODULE_NOSUPPORT_WEBAPP;
  13. $xzapp_support = in_array('xzapp', $manifest['platform']['supports']) ? MODULE_SUPPORT_XZAPP : MODULE_NOSUPPORT_XZAPP;
  14. $aliapp_support = in_array('aliapp', $manifest['platform']['supports']) ? MODULE_SUPPORT_ALIAPP : MODULE_NOSUPPORT_ALIAPP;
  15. $android_support = in_array('android', $manifest['platform']['supports']) ? MODULE_SUPPORT_ANDROID : MODULE_NOSUPPORT_ANDROID;
  16. $ios_support = in_array('ios', $manifest['platform']['supports']) ? MODULE_SUPPORT_IOS : MODULE_NOSUPPORT_IOS;
  17. $phoneapp_support = ($android_support == MODULE_SUPPORT_ANDROID || $ios_support == MODULE_SUPPORT_IOS) ? MODULE_SUPPORT_PHONEAPP : MODULE_NOSUPPORT_PHONEAPP;
  18. if ($app_support == MODULE_NONSUPPORT_ACCOUNT && $wxapp_support == MODULE_NONSUPPORT_WXAPP && $welcome_support == MODULE_NONSUPPORT_SYSTEMWELCOME && $webapp_support == MODULE_NOSUPPORT_WEBAPP && $phoneapp_support == MODULE_NOSUPPORT_PHONEAPP) {
  19. $app_support = MODULE_SUPPORT_ACCOUNT;
  20. }
  21. } else {
  22. $app_support = MODULE_SUPPORT_ACCOUNT;
  23. $wxapp_support = MODULE_NONSUPPORT_WXAPP;
  24. }
  25. return array(
  26. 'name' => $manifest['application']['identifie'],
  27. 'title' => $manifest['application']['name'],
  28. 'version' => $manifest['application']['version'],
  29. 'type' => $manifest['application']['type'],
  30. 'ability' => $manifest['application']['ability'],
  31. 'description' => $manifest['application']['description'],
  32. 'author' => $manifest['application']['author'],
  33. 'url' => $manifest['application']['url'],
  34. 'settings' => intval($manifest['application']['setting']),
  35. 'subscribes' => iserializer(is_array($manifest['platform']['subscribes']) ? $manifest['platform']['subscribes'] : array()),
  36. 'handles' => iserializer(is_array($manifest['platform']['handles']) ? $manifest['platform']['handles'] : array()),
  37. 'isrulefields' => intval($manifest['platform']['isrulefields']),
  38. 'iscard' => intval($manifest['platform']['iscard']),
  39. 'oauth_type' => $manifest['platform']['oauth_type'],
  40. 'page' => $manifest['bindings']['page'],
  41. 'cover' => $manifest['bindings']['cover'],
  42. 'rule' => $manifest['bindings']['rule'],
  43. 'menu' => $manifest['bindings']['menu'],
  44. 'home' => $manifest['bindings']['home'],
  45. 'profile' => $manifest['bindings']['profile'],
  46. 'system_welcome' => $manifest['bindings']['system_welcome'],
  47. 'webapp' => $manifest['bindings']['webapp'],
  48. 'phoneapp' => $manifest['bindings']['phoneapp'],
  49. MODULE_SUPPORT_ACCOUNT_NAME => $app_support,
  50. 'wxapp_support' => $wxapp_support,
  51. 'webapp_support' => $webapp_support,
  52. 'phoneapp_support' => $phoneapp_support,
  53. 'xzapp_support' => $xzapp_support,
  54. 'aliapp_support' => $aliapp_support,
  55. 'welcome_support' => $welcome_support,
  56. 'shortcut' => $manifest['bindings']['shortcut'],
  57. 'function' => $manifest['bindings']['function'],
  58. 'permissions' => $manifest['permissions'],
  59. 'issystem' => 0,
  60. );
  61. }
  62. function ext_module_manifest_parse($xml) {
  63. if (!strexists($xml, '<manifest')) {
  64. $xml = base64_decode($xml);
  65. }
  66. if (empty($xml)) {
  67. return array();
  68. }
  69. $dom = new DOMDocument();
  70. $dom->loadXML($xml);
  71. $root = $dom->getElementsByTagName('manifest')->item(0);
  72. if (empty($root)) {
  73. return array();
  74. }
  75. $vcode = explode(',', $root->getAttribute('versionCode'));
  76. $manifest['versions'] = array();
  77. if (is_array($vcode)) {
  78. foreach ($vcode as $v) {
  79. $v = trim($v);
  80. if (!empty($v)) {
  81. $manifest['versions'][] = $v;
  82. }
  83. }
  84. $manifest['versions'][] = '0.52';
  85. $manifest['versions'][] = '0.6';
  86. $manifest['versions'] = array_unique($manifest['versions']);
  87. }
  88. $manifest['install'] = $root->getElementsByTagName('install')->item(0)->textContent;
  89. $manifest['uninstall'] = $root->getElementsByTagName('uninstall')->item(0)->textContent;
  90. $manifest['upgrade'] = $root->getElementsByTagName('upgrade')->item(0)->textContent;
  91. $application = $root->getElementsByTagName('application')->item(0);
  92. if (empty($application)) {
  93. return array();
  94. }
  95. $manifest['application'] = array(
  96. 'name' => trim($application->getElementsByTagName('name')->item(0)->textContent),
  97. 'identifie' => trim($application->getElementsByTagName('identifie')->item(0)->textContent),
  98. 'version' => trim($application->getElementsByTagName('version')->item(0)->textContent),
  99. 'type' => trim($application->getElementsByTagName('type')->item(0)->textContent),
  100. 'ability' => trim($application->getElementsByTagName('ability')->item(0)->textContent),
  101. 'description' => trim($application->getElementsByTagName('description')->item(0)->textContent),
  102. 'author' => trim($application->getElementsByTagName('author')->item(0)->textContent),
  103. 'url' => trim($application->getElementsByTagName('url')->item(0)->textContent),
  104. 'setting' => trim($application->getAttribute('setting')) == 'true',
  105. );
  106. $platform = $root->getElementsByTagName('platform')->item(0);
  107. if (!empty($platform)) {
  108. $manifest['platform'] = array(
  109. 'subscribes' => array(),
  110. 'handles' => array(),
  111. 'isrulefields' => false,
  112. 'iscard' => false,
  113. 'supports' => array(),
  114. 'oauth_type' => OAUTH_TYPE_BASE,
  115. );
  116. $subscribes = $platform->getElementsByTagName('subscribes')->item(0);
  117. if (!empty($subscribes)) {
  118. $messages = $subscribes->getElementsByTagName('message');
  119. for ($i = 0; $i < $messages->length; $i++) {
  120. $t = $messages->item($i)->getAttribute('type');
  121. if (!empty($t)) {
  122. $manifest['platform']['subscribes'][] = $t;
  123. }
  124. }
  125. }
  126. $handles = $platform->getElementsByTagName('handles')->item(0);
  127. if (!empty($handles)) {
  128. $messages = $handles->getElementsByTagName('message');
  129. for ($i = 0; $i < $messages->length; $i++) {
  130. $t = $messages->item($i)->getAttribute('type');
  131. if (!empty($t)) {
  132. $manifest['platform']['handles'][] = $t;
  133. }
  134. }
  135. }
  136. $rule = $platform->getElementsByTagName('rule')->item(0);
  137. if (!empty($rule) && $rule->getAttribute('embed') == 'true') {
  138. $manifest['platform']['isrulefields'] = true;
  139. }
  140. $card = $platform->getElementsByTagName('card')->item(0);
  141. if (!empty($card) && $card->getAttribute('embed') == 'true') {
  142. $manifest['platform']['iscard'] = true;
  143. }
  144. $oauth_type = $platform->getElementsByTagName('oauth')->item(0);
  145. if (!empty($oauth_type) && $oauth_type->getAttribute('type') == OAUTH_TYPE_USERINFO) {
  146. $manifest['platform']['oauth_type'] = OAUTH_TYPE_USERINFO;
  147. }
  148. $supports = $platform->getElementsByTagName('supports')->item(0);
  149. if (!empty($supports)) {
  150. $support_type = $supports->getElementsByTagName('item');
  151. for ($i = 0; $i < $support_type->length; $i++) {
  152. $t = $support_type->item($i)->getAttribute('type');
  153. if (!empty($t)) {
  154. $manifest['platform']['supports'][] = $t;
  155. }
  156. }
  157. }
  158. $plugins = $platform->getElementsByTagName('plugins')->item(0);
  159. if (!empty($plugins)) {
  160. $plugin_list = $plugins->getElementsByTagName('item');
  161. for ($i = 0; $i < $plugin_list->length; $i++) {
  162. $plugin = $plugin_list->item($i)->getAttribute('name');
  163. if (!empty($plugin)) {
  164. $manifest['platform']['plugin_list'][] = $plugin;
  165. }
  166. }
  167. }
  168. $plugin_main = $platform->getElementsByTagName('plugin-main')->item(0);
  169. if (!empty($plugin_main)) {
  170. $plugin_main = $plugin_main->getAttribute('name');
  171. if (!empty($plugin_main)) {
  172. $manifest['platform']['main_module'] = $plugin_main;
  173. }
  174. }
  175. }
  176. $bindings = $root->getElementsByTagName('bindings')->item(0);
  177. if (!empty($bindings)) {
  178. $points = ext_module_bindings();
  179. if (!empty($points)) {
  180. $ps = array_keys($points);
  181. $manifest['bindings'] = array();
  182. foreach ($ps as $p) {
  183. $define = $bindings->getElementsByTagName($p)->item(0);
  184. $manifest['bindings'][$p] = _ext_module_manifest_entries($define);
  185. }
  186. }
  187. }
  188. $permissions = $root->getElementsByTagName('permissions')->item(0);
  189. if (!empty($permissions)) {
  190. $manifest['permissions'] = array();
  191. $items = $permissions->getElementsByTagName('entry');
  192. for ($i = 0; $i < $items->length; $i++) {
  193. $item = $items->item($i);
  194. $row = array(
  195. 'title' => $item->getAttribute('title'),
  196. 'permission' => $item->getAttribute('do'),
  197. );
  198. if (!empty($row['title']) && !empty($row['permission'])) {
  199. $manifest['permissions'][] = $row;
  200. }
  201. }
  202. }
  203. return $manifest;
  204. }
  205. function ext_module_manifest($modulename) {
  206. $root = IA_ROOT . '/addons/' . $modulename;
  207. $filename = $root . '/manifest.xml';
  208. if (!file_exists($filename)) {
  209. return array();
  210. }
  211. $xml = file_get_contents($filename);
  212. $xml = ext_module_manifest_parse($xml);
  213. if (!empty($xml)) {
  214. $xml['application']['logo'] = tomedia($root . '/icon.jpg');
  215. if (file_exists($root . '/preview-custom.jpg')) {
  216. $xml['application']['preview'] = tomedia($root . '/preview-custom.jpg');
  217. } else {
  218. $xml['application']['preview'] = tomedia($root . '/preview.jpg');
  219. }
  220. if (empty($xml['platform']['supports'])) {
  221. $xml['platform']['supports'][] = 'app';
  222. }
  223. }
  224. return $xml;
  225. }
  226. function _ext_module_manifest_entries($elm) {
  227. $ret = array();
  228. if (!empty($elm)) {
  229. $call = $elm->getAttribute('call');
  230. if (!empty($call)) {
  231. $ret[] = array('call' => $call);
  232. }
  233. $entries = $elm->getElementsByTagName('entry');
  234. for ($i = 0; $i < $entries->length; $i++) {
  235. $entry = $entries->item($i);
  236. $direct = $entry->getAttribute('direct');
  237. $row = array(
  238. 'title' => $entry->getAttribute('title'),
  239. 'do' => $entry->getAttribute('do'),
  240. 'direct' => !empty($direct) && $direct != 'false' ? true : false,
  241. 'state' => $entry->getAttribute('state'),
  242. 'icon' => $entry->getAttribute('icon')
  243. );
  244. if (!empty($row['title']) && !empty($row['do'])) {
  245. $ret[] = $row;
  246. }
  247. }
  248. }
  249. return $ret;
  250. }
  251. function ext_module_checkupdate($modulename) {
  252. $manifest = ext_module_manifest($modulename);
  253. if (!empty($manifest) && is_array($manifest)) {
  254. $version = $manifest['application']['version'];
  255. load()->model('module');
  256. $module = module_fetch($modulename);
  257. if (version_compare($version, $module['version']) == '1') {
  258. return true;
  259. } else {
  260. return false;
  261. }
  262. } else {
  263. return false;
  264. }
  265. }
  266. function ext_module_bindings() {
  267. static $bindings = array(
  268. 'cover' => array(
  269. 'name' => 'cover',
  270. 'title' => '功能封面',
  271. 'desc' => '功能封面是定义微站里一个独立功能的入口(手机端操作), 将呈现为一个图文消息, 点击后进入微站系统中对应的功能.'
  272. ),
  273. 'rule' => array(
  274. 'name' => 'rule',
  275. 'title' => '规则列表',
  276. 'desc' => '规则列表是定义可重复使用或者可创建多次的活动的功能入口(管理后台Web操作), 每个活动对应一条规则. 一般呈现为图文消息, 点击后进入定义好的某次活动中.'
  277. ),
  278. 'menu' => array(
  279. 'name' => 'menu',
  280. 'title' => '管理中心导航菜单',
  281. 'desc' => '管理中心导航菜单将会在管理中心生成一个导航入口(管理后台Web操作), 用于对模块定义的内容进行管理.'
  282. ),
  283. 'home' => array(
  284. 'name' => 'home',
  285. 'title' => '微站首页导航图标',
  286. 'desc' => '在微站的首页上显示相关功能的链接入口(手机端操作), 一般用于通用功能的展示.'
  287. ),
  288. 'profile'=> array(
  289. 'name' => 'profile',
  290. 'title' => '微站个人中心导航',
  291. 'desc' => '在微站的个人中心上显示相关功能的链接入口(手机端操作), 一般用于个人信息, 或针对个人的数据的展示.'
  292. ),
  293. 'shortcut'=> array(
  294. 'name' => 'shortcut',
  295. 'title' => '微站快捷功能导航',
  296. 'desc' => '在微站的快捷菜单上展示相关功能的链接入口(手机端操作), 仅在支持快捷菜单的微站模块上有效.'
  297. ),
  298. 'function'=> array(
  299. 'name' => 'function',
  300. 'title' => '微站独立功能',
  301. 'desc' => '需要特殊定义的操作, 一般用于将指定的操作指定为(direct). 如果一个操作没有在具体位置绑定, 但是需要定义为(direct: 直接访问), 可以使用这个嵌入点'
  302. ),
  303. 'page'=> array(
  304. 'name' => 'page',
  305. 'title' => '小程序入口',
  306. 'desc' => '用于小程序入口的链接'
  307. ),
  308. 'system_welcome' => array(
  309. 'name' => 'system_welcome',
  310. 'title' => '系统首页导航菜单',
  311. 'desc' => '系统首页导航菜单将会在管理中心生成一个导航入口, 用于对系统首页定义的内容进行管理.',
  312. ),
  313. 'webapp' => array(
  314. 'name' => 'webapp',
  315. 'title' => 'PC入口',
  316. 'desc' => '用于PC入口的链接',
  317. ),
  318. 'phoneapp' => array(
  319. 'name' => 'phoneapp',
  320. 'title' => 'APP入口',
  321. 'desc' => '用于APP入口的链接',
  322. )
  323. );
  324. return $bindings;
  325. }
  326. function ext_module_clean($modulename, $is_clean_rule = false) {
  327. pdo_delete('core_queue', array('module' => $modulename));
  328. table('modules')->deleteByName($modulename);
  329. table('modules_bindings')->deleteByName($modulename);
  330. pdo_delete('modules_plugin', array('main_module' => $modulename));
  331. if ($is_clean_rule) {
  332. pdo_delete('rule', array('module' => $modulename));
  333. pdo_delete('rule_keyword', array('module' => $modulename));
  334. $cover_list = pdo_getall('cover_reply', array('module' => $modulename), array('rid'), 'rid');
  335. if (!empty($cover_list)) {
  336. $rids = array_keys($cover_list);
  337. pdo_delete('rule_keyword', array('module' => 'cover', 'rid' => $rids));
  338. pdo_delete('rule', array('module' => 'cover', 'id' => $rids));
  339. pdo_delete('cover_reply', array('module' => $modulename));
  340. }
  341. }
  342. pdo_delete('site_nav', array('module' => $modulename));
  343. pdo_delete('uni_account_modules', array('module' => $modulename));
  344. pdo_delete('users_permission', array('type' => $modulename));
  345. table('modules_recycle')->deleteByName($modulename);
  346. $uni_group = pdo_getall('uni_group');
  347. if (!empty($uni_group)) {
  348. foreach ($uni_group as $group) {
  349. $update = false;
  350. $modules = (array)iunserializer($group['modules']);
  351. if (!empty($modules)) {
  352. foreach ($modules as $type => $value) {
  353. if (!empty($value) && in_array($modulename, $value)) {
  354. $modules[$type] = array_diff($modules[$type], array($modulename));
  355. $update = true;
  356. }
  357. }
  358. if ($update) {
  359. pdo_update('uni_group', array('modules' => iserializer($modules)), array('id' => $group['id']));
  360. }
  361. }
  362. }
  363. }
  364. return true;
  365. }
  366. function ext_template_manifest($tpl, $cloud = true) {
  367. $filename = IA_ROOT . '/app/themes/' . $tpl . '/manifest.xml';
  368. if (!file_exists($filename)) {
  369. if ($cloud) {
  370. load()->model('cloud');
  371. $manifest = cloud_t_info($tpl);
  372. }
  373. return is_error($manifest) ? array() : $manifest;
  374. }
  375. $manifest = ext_template_manifest_parse(file_get_contents($filename));
  376. if (empty($manifest['name']) || $manifest['name'] != $tpl) {
  377. return array();
  378. }
  379. return $manifest;
  380. }
  381. function ext_template_manifest_parse($xml) {
  382. $xml = str_replace(array('&'), array('&amp;'), $xml);
  383. $xml = @isimplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  384. if (empty($xml)) {
  385. return array();
  386. }
  387. $manifest['name'] = strval($xml->identifie);
  388. $manifest['title'] = strval($xml->title);
  389. if (empty($manifest['title'])) {
  390. return array();
  391. }
  392. $manifest['type'] = !empty($xml->type) ? strval($xml->type) : 'other';
  393. $manifest['description'] = strval($xml->description);
  394. $manifest['author'] = strval($xml->author);
  395. $manifest['url'] = strval($xml->url);
  396. if (isset($xml->sections)) {
  397. $manifest['sections'] = strval($xml->sections);
  398. }
  399. if ($xml->settings->item) {
  400. foreach ($xml->settings->item as $msg) {
  401. $attrs = $msg->attributes();
  402. $manifest['settings'][] = array('key' => trim(strval($attrs['variable'])), 'value' => trim(strval($attrs['content'])), 'desc' => trim(strval($attrs['description'])));
  403. }
  404. }
  405. return $manifest;
  406. }
  407. function ext_template_type() {
  408. static $types = array(
  409. 'often' => array(
  410. 'name' => 'often',
  411. 'title' => '常用模板',
  412. ),
  413. 'rummery' => array(
  414. 'name' => 'rummery',
  415. 'title' => '酒店',
  416. ),
  417. 'car' => array(
  418. 'name' => 'car',
  419. 'title' => '汽车',
  420. ),
  421. 'tourism' => array(
  422. 'name' => 'tourism',
  423. 'title' => '旅游',
  424. ),
  425. 'drink' => array(
  426. 'name' => 'drink',
  427. 'title' => '餐饮',
  428. ),
  429. 'realty' => array(
  430. 'name' => 'realty',
  431. 'title' => '房地产',
  432. ),
  433. 'medical' => array(
  434. 'name' => 'medical',
  435. 'title' => '医疗保健'
  436. ),
  437. 'education' => array(
  438. 'name' => 'education',
  439. 'title' => '教育'
  440. ),
  441. 'cosmetology' => array(
  442. 'name' => 'cosmetology',
  443. 'title' => '健身美容'
  444. ),
  445. 'shoot' => array(
  446. 'name' => 'shoot',
  447. 'title' => '婚纱摄影'
  448. ),
  449. 'other' => array(
  450. 'name' => 'other',
  451. 'title' => '其它行业'
  452. )
  453. );
  454. return $types;
  455. }
  456. function ext_module_script_clean($modulename, $manifest) {
  457. $moduleDir = IA_ROOT . '/addons/' . $modulename . '/';
  458. $manifest['install'] = trim($manifest['install']);
  459. $manifest['uninstall'] = trim($manifest['uninstall']);
  460. $manifest['upgrade'] = trim($manifest['upgrade']);
  461. if (strexists($manifest['install'], '.php')) {
  462. if (file_exists($moduleDir . $manifest['install'])) {
  463. unlink($moduleDir . $manifest['install']);
  464. }
  465. }
  466. if (strexists($manifest['uninstall'], '.php')) {
  467. if (file_exists($moduleDir . $manifest['uninstall'])) {
  468. unlink($moduleDir . $manifest['uninstall']);
  469. }
  470. }
  471. if (strexists($manifest['upgrade'], '.php')) {
  472. if (file_exists($moduleDir . $manifest['upgrade'])) {
  473. unlink($moduleDir . $manifest['upgrade']);
  474. }
  475. }
  476. if (file_exists($moduleDir . 'manifest.xml')) {
  477. unlink($moduleDir . 'manifest.xml');
  478. }
  479. }
  480. function ext_module_msg_types() {
  481. $mtypes = array();
  482. $mtypes['text'] = '文本消息(重要)';
  483. $mtypes['image'] = '图片消息';
  484. $mtypes['voice'] = '语音消息';
  485. $mtypes['video'] = '视频消息';
  486. $mtypes['shortvideo'] = '小视频消息';
  487. $mtypes['location'] = '位置消息';
  488. $mtypes['link'] = '链接消息';
  489. $mtypes['subscribe'] = '粉丝开始关注';
  490. $mtypes['unsubscribe'] = '粉丝取消关注';
  491. $mtypes['qr'] = '扫描二维码';
  492. $mtypes['trace'] = '追踪地理位置';
  493. $mtypes['click'] = '点击菜单(模拟关键字)';
  494. $mtypes['view'] = '点击菜单(链接)';
  495. $mtypes['merchant_order'] = '微小店消息';
  496. $mtypes['user_get_card'] = '用户领取卡券事件';
  497. $mtypes['user_del_card'] = '用户删除卡券事件';
  498. $mtypes['user_consume_card'] = '用户核销卡券事件';
  499. return $mtypes;
  500. }
  501. function ext_check_module_subscribe($modulename) {
  502. global $_W, $_GPC;
  503. if (empty($modulename)) {
  504. return true;
  505. }
  506. if (!is_array($_W['setting']['module_receive_ban'])) {
  507. $_W['setting']['module_receive_ban'] = array();
  508. }
  509. load()->func('communication');
  510. $response = ihttp_request($_W['siteroot'] . 'web/' . url('utility/modules/check_receive', array('module_name' => $modulename)));
  511. $response['content'] = json_decode($response['content'], true);
  512. if (empty($response['content']['message']['errno'])) {
  513. unset($_W['setting']['module_receive_ban'][$modulename]);
  514. $module_subscribe_success = true;
  515. } else {
  516. $_W['setting']['module_receive_ban'][$modulename] = $modulename;
  517. $module_subscribe_success = false;
  518. }
  519. setting_save($_W['setting']['module_receive_ban'], 'module_receive_ban');
  520. return $module_subscribe_success;
  521. }
  522. function ext_manifest_check($module_name, $manifest) {
  523. if(is_string($manifest)) {
  524. return error(1, '模块配置项定义错误, 具体错误内容为: <br />' . $manifest);
  525. }
  526. if(empty($manifest['application']['name'])) {
  527. return error(1, '模块名称未定义. ');
  528. }
  529. if(empty($manifest['application']['identifie']) || !preg_match('/^[a-z][a-z\d_]+$/i', $manifest['application']['identifie'])) {
  530. return error(1, '模块标识符未定义或格式错误(仅支持字母和数字, 且只能以字母开头).');
  531. }
  532. if(strtolower($module_name) != strtolower($manifest['application']['identifie'])) {
  533. return error(1, '模块名称定义与模块路径名称定义不匹配. ');
  534. }
  535. if(empty($manifest['application']['version']) || !preg_match('/^[\d\.]+$/i', $manifest['application']['version'])) {
  536. return error(1, '模块版本号未定义(仅支持数字和句点). ');
  537. }
  538. if(empty($manifest['application']['ability'])) {
  539. return error(1, '模块功能简述未定义. ');
  540. }
  541. if($manifest['platform']['isrulefields'] && !in_array('text', $manifest['platform']['handles'])) {
  542. return error(1, '模块功能定义错误, 嵌入规则必须要能够处理文本类型消息.. ');
  543. }
  544. if((!empty($manifest['cover']) || !empty($manifest['rule'])) && !$manifest['platform']['isrulefields']) {
  545. return error(1, '模块功能定义错误, 存在封面或规则功能入口绑定时, 必须要嵌入规则. ');
  546. }
  547. global $points;
  548. if (!empty($points)) {
  549. foreach($points as $name => $point) {
  550. if(is_array($manifest[$name])) {
  551. foreach($manifest[$name] as $menu) {
  552. if(trim($menu['title']) == '' || !preg_match('/^[a-z\d]+$/i', $menu['do']) && empty($menu['call'])) {
  553. return error(1, $point['title'] . ' 扩展项功能入口定义错误, (操作标题[title], 入口方法[do])格式不正确.');
  554. }
  555. }
  556. }
  557. }
  558. }
  559. if(is_array($manifest['permissions']) && !empty($manifest['permissions'])) {
  560. foreach($manifest['permissions'] as $permission) {
  561. if(trim($permission['title']) == '' || !preg_match('/^[a-z\d_]+$/i', $permission['permission'])) {
  562. return error(1, "名称为: {$permission['title']} 的权限标识格式不正确,请检查标识名称或标识格式是否正确");
  563. }
  564. }
  565. }
  566. if(!is_array($manifest['versions'])) {
  567. return error(1, '兼容版本格式错误');
  568. }
  569. return error(0);
  570. }
  571. function ext_file_check($module_name, $manifest) {
  572. $module_path = IA_ROOT . '/addons/' . $module_name . '/';
  573. if (empty($manifest['platform']['main_module']) &&
  574. !file_exists($module_path . 'processor.php') &&
  575. !file_exists($module_path . 'module.php') &&
  576. !file_exists($module_path . 'site.php')) {
  577. return error(1, '模块缺失文件,请检查模块文件中site.php, processor.php, module.php, receiver.php 文件是否存在!');
  578. }
  579. return true;
  580. }
  581. function ext_module_uninstall($modulename, $is_clean_rule = false) {
  582. global $_W;
  583. $modulename = trim($modulename);
  584. if (empty($modulename)) {
  585. return error(1, '模块已经被卸载或是不存在!');
  586. }
  587. $module = module_fetch($modulename, false);
  588. if (empty($module)) {
  589. return error(1, '模块已经被卸载或是不存在!');
  590. }
  591. if (!empty($module['issystem'])) {
  592. return error(1, '系统模块不能卸载!');
  593. }
  594. ext_module_clean($modulename, $is_clean_rule);
  595. ext_execute_uninstall_script($modulename);
  596. return true;
  597. }
  598. function ext_execute_uninstall_script($module_name) {
  599. global $_W;
  600. load()->model('cloud');
  601. $modulepath = IA_ROOT . '/addons/' . $module_name . '/';
  602. $manifest = ext_module_manifest($module_name);
  603. if (empty($manifest)) {
  604. $result = cloud_prepare();
  605. if (is_error($result)) {
  606. return error(1, $result['message']);
  607. }
  608. $packet = cloud_m_build($module_name, 'uninstall');
  609. if ($packet['sql']) {
  610. pdo_run(base64_decode($packet['sql']));
  611. } elseif ($packet['script']) {
  612. $uninstall_file = $modulepath . TIMESTAMP . '.php';
  613. file_put_contents($uninstall_file, base64_decode($packet['script']));
  614. require($uninstall_file);
  615. unlink($uninstall_file);
  616. }
  617. } else {
  618. if (!empty($manifest['uninstall'])) {
  619. if (strexists($manifest['uninstall'], '.php')) {
  620. if (file_exists($modulepath . $manifest['uninstall'])) {
  621. require($modulepath . $manifest['uninstall']);
  622. }
  623. } else {
  624. pdo_run($manifest['uninstall']);
  625. }
  626. }
  627. }
  628. return true;
  629. }
  630. function ext_module_run_script($manifest, $scripttype) {
  631. if (!in_array($scripttype, array('install', 'upgrade'))) {
  632. return false;
  633. }
  634. $modulename = $manifest['application']['identifie'];
  635. $module_path = IA_ROOT . '/addons/' . $modulename . '/';
  636. if (!empty($manifest[$scripttype])) {
  637. if (strexists($manifest[$scripttype], '.php')) {
  638. if (file_exists($module_path . $manifest[$scripttype])) {
  639. include_once $module_path . $manifest[$scripttype];
  640. }
  641. } else {
  642. pdo_run($manifest[$scripttype]);
  643. }
  644. }
  645. if (defined('ONLINE_MODULE')) {
  646. ext_module_script_clean($modulename, $manifest);
  647. }
  648. return true;
  649. }