extension.mod.php 25 KB

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