extension.mod.php 27 KB

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