extension.mod.php 23 KB

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