人人商城

module.ctrl.php 39KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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. load()->model('extension');
  8. load()->model('cloud');
  9. load()->model('cache');
  10. load()->func('file');
  11. $dos = array('installed', 'check', 'prepared', 'install', 'upgrade', 'uninstall', 'designer', 'permission', 'batch-install', 'info', 'recycle');
  12. $do = in_array($do, $dos) ? $do : 'installed';
  13. $points = ext_module_bindings();
  14. $sysmodules = system_modules();
  15. if ($do == 'recycle') {
  16. $operate = $_GPC['op'];
  17. $name = trim($_GPC['name']);
  18. if ($operate == 'delete') {
  19. pdo_insert('modules_recycle', array('modulename' => $name));
  20. message('模块已放入回收站', url('extension/module/prepared', array('status' => 'recycle')), 'success');
  21. } elseif ($operate == 'recover') {
  22. pdo_delete('modules_recycle', array('modulename' => $name));
  23. message('模块恢复成功', url('extension/module/install', array('m' => $name)), 'success');
  24. }
  25. template('extension/module');
  26. }
  27. if($do == 'batch-install') {
  28. if(empty($_W['isfounder'])) {
  29. message('您没有安装模块的权限', '', 'error');
  30. }
  31. if($_W['ispost']) {
  32. $modulename = $_GPC['m_name'];
  33. if(pdo_fetchcolumn("SELECT mid FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $modulename))) {
  34. exit('error');
  35. }
  36. $modulepath = IA_ROOT . '/addons/' . $modulename . '/';
  37. $manifest = ext_module_manifest($modulename);
  38. if (!empty($manifest)) {
  39. $r = cloud_m_prepare($modulename);
  40. if(is_error($r)) {
  41. exit('error');
  42. }
  43. }
  44. if(empty($manifest)) {
  45. exit('error');
  46. }
  47. manifest_check($modulename, $manifest);
  48. if(pdo_fetchcolumn("SELECT mid FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $manifest['application']['identifie']))) {
  49. exit('error');
  50. }
  51. if(!file_exists($modulepath . 'processor.php') && !file_exists($modulepath . 'module.php') && !file_exists($modulepath . 'receiver.php') && !file_exists($modulepath . 'site.php')) {
  52. exit('error');
  53. }
  54. $module = ext_module_convert($manifest);
  55. ext_module_clean($modulename);
  56. $bindings = array_elements(array_keys($points), $module, false);
  57. foreach($points as $p => $row) {
  58. unset($module[$p]);
  59. if(is_array($bindings[$p]) && !empty($bindings[$p])) {
  60. foreach($bindings[$p] as $entry) {
  61. $entry['module'] = $manifest['application']['identifie'];
  62. $entry['entry'] = $p;
  63. pdo_insert('modules_bindings', $entry);
  64. }
  65. }
  66. }
  67. $module['permissions'] = iserializer($module['permissions']);
  68. if(pdo_insert('modules', $module)) {
  69. load()->model('module');
  70. module_build_privileges();
  71. cache_build_account_modules();
  72. if(strexists($manifest['install'], '.php')) {
  73. if(file_exists($modulepath . $manifest['install'])) {
  74. include_once $modulepath . $manifest['install'];
  75. }
  76. } else {
  77. pdo_run($manifest['install']);
  78. }
  79. update_handle($module['name']);
  80. exit('success');
  81. } else {
  82. exit('error');
  83. }
  84. }
  85. }
  86. if($do == 'info') {
  87. $m = trim($_GPC['m']);
  88. if($_W['isajax']) {
  89. $data = pdo_fetch('SELECT name, title, ability, description FROM ' . tablename('modules') . ' WHERE name = :m', array(':m' => $m));
  90. exit(json_encode($data));
  91. } else {
  92. if(checksubmit('submit')) {
  93. $update = array();
  94. !empty($_GPC['title']) && $update['title'] = $_GPC['title'];
  95. !empty($_GPC['ability']) && $update['ability'] = $_GPC['ability'];
  96. !empty($_GPC['description']) && $update['description'] = $_GPC['description'];
  97. if(!empty($update)) {
  98. pdo_update('modules', $update, array('name' => $m));
  99. cache_build_account_modules();
  100. }
  101. $sysmodules = system_modules();
  102. if(in_array($m, $sysmodules)) {
  103. $root = IA_ROOT . '/framework/builtin/' . $m;
  104. } else {
  105. $root = IA_ROOT . '/addons/' . $m;
  106. }
  107. if($_FILES['icon'] && $_FILES['icon']['error'] == '0' && !empty($_FILES['icon']['tmp_name'])) {
  108. $icon = $_FILES['icon']['tmp_name'];
  109. }
  110. if($_FILES['preview'] && $_FILES['preview']['error'] == '0' && !empty($_FILES['preview']['tmp_name'])) {
  111. $preview = $_FILES['preview']['tmp_name'];
  112. }
  113. load()->func('file');
  114. mkdirs($root);
  115. if($icon) {
  116. file_move($icon, "{$root}/icon-custom.jpg");
  117. }
  118. if($preview) {
  119. file_move($preview, "{$root}/preview-custom.jpg");
  120. }
  121. message('更新模块信息成功', referer(), 'success');
  122. }
  123. }
  124. }
  125. if($do == 'installed') {
  126. $_W['page']['title'] = '已安装的模块 - 模块 - 扩展';
  127. load()->model('module');
  128. $modtypes = module_types();
  129. $modules = pdo_fetchall("SELECT * FROM " . tablename('modules') .' ORDER BY `issystem` DESC, `mid` ASC', array(), 'mid');
  130. if (!empty($modules)) {
  131. foreach ($modules as $mid => $module) {
  132. $manifest = ext_module_manifest($module['name']);
  133. $modules[$mid]['official'] = empty($module['issystem']) && (strexists($module['author'], 'WeEngine Team') || strexists($module['author'], ' '));
  134. $modules[$mid]['description'] = strip_tags($module['description']);
  135. if(is_array($manifest) && ver_compare($module['version'], $manifest['application']['version']) == '-1') {
  136. $modules[$mid]['upgrade'] = true;
  137. }
  138. if(in_array($module['name'], $sysmodules)) {
  139. $modules[$mid]['imgsrc'] = '../framework/builtin/' . $module['name'] . '/icon-custom.jpg';
  140. if(!file_exists($modules[$mid]['imgsrc'])) {
  141. $modules[$mid]['imgsrc'] = '../framework/builtin/' . $module['name'] . '/icon.jpg';
  142. }
  143. } else {
  144. $modules[$mid]['imgsrc'] = '../addons/' . $module['name'] . '/icon-custom.jpg';
  145. if(!file_exists($modules[$mid]['imgsrc'])) {
  146. $modules[$mid]['imgsrc'] = '../addons/' . $module['name'] . '/icon.jpg';
  147. }
  148. }
  149. }
  150. }
  151. $sysmodules = implode("', '", $sysmodules);
  152. template('extension/module');
  153. }
  154. if ($do == 'check') {
  155. if ($_W['isajax']) {
  156. $foo = $_GPC['foo'];
  157. $r = cloud_prepare();
  158. if (is_error($r)) {
  159. exit('cloud service is unavailable');
  160. }
  161. if ($foo == 'upgrade') {
  162. $mods = array();
  163. $ret = cloud_m_query();
  164. if (!is_error($ret)) {
  165. foreach ($ret as $k => $v) {
  166. $mods[$k] = array(
  167. 'from' => 'cloud',
  168. 'version' => $v['version'],
  169. 'name' => $v['name'],
  170. 'branches' => $v['branches'],
  171. 'site_branch' => $v['branches'][$v['branch']],
  172. );
  173. }
  174. $mods['pirate_apps'] = $ret['pirate_apps'];
  175. }
  176. if (!empty($mods)) {
  177. exit(json_encode($mods));
  178. } else {
  179. exit(json_encode(array('')));
  180. }
  181. } else {
  182. $moduleids = array();
  183. $modules = pdo_fetchall("SELECT `name` FROM " . tablename('modules') . ' ORDER BY `issystem` DESC, `mid` ASC');
  184. if (!empty($modules)) {
  185. foreach ($modules as $m) {
  186. $moduleids[] = $m['name'];
  187. }
  188. }
  189. $ret = cloud_m_query();
  190. if (!is_error($ret)) {
  191. $cloudUninstallModules = array();
  192. if ($ret['pirate_apps']) {
  193. unset($ret['pirate_apps']);
  194. }
  195. foreach ($ret as $k => $v) {
  196. if (!in_array(strtolower($k), $moduleids) && $v['id']) {
  197. $v['name'] = $k;
  198. $cloudUninstallModules[] = $v;
  199. $moduleids[] = $k;
  200. }
  201. }
  202. foreach ($cloudUninstallModules as &$cloudUninstallModule) {
  203. $cloudUninstallModule['description'] = strip_tags($cloudUninstallModule['description']);
  204. }
  205. exit(json_encode($cloudUninstallModules));
  206. }
  207. }
  208. }
  209. exit('failure');
  210. }
  211. if($do == 'prepared') {
  212. $_W['page']['title'] = '安装模块 - 模块 - 扩展';
  213. $status = $_GPC['status'];
  214. $recycle_modules = pdo_getall('modules_recycle', array(), array(), 'modulename');
  215. $recycle_modules = array_keys($recycle_modules);
  216. $moduleids = array();
  217. $modules = pdo_fetchall("SELECT `name` FROM " . tablename('modules') . ' ORDER BY `issystem` DESC, `mid` ASC');
  218. if(!empty($modules)) {
  219. foreach($modules as $m) {
  220. $moduleids[] = $m['name'];
  221. }
  222. }
  223. $path = IA_ROOT . '/addons/';
  224. if (is_dir($path)) {
  225. $localUninstallModules_noso = array();
  226. $localUninstallModules_title = array();
  227. $localUninstallModules = array();
  228. if ($handle = opendir($path)) {
  229. while (false !== ($modulepath = readdir($handle))) {
  230. $manifest = ext_module_manifest($modulepath);
  231. if (!empty($status) && in_array($manifest['application']['identifie'], $recycle_modules) || empty($status) && !in_array($manifest['application']['identifie'], $recycle_modules)) {
  232. if (is_array($manifest) && !empty($manifest['application']['identifie']) && !in_array($manifest['application']['identifie'], $moduleids)) {
  233. $m = ext_module_convert($manifest);
  234. $localUninstallModules[$m['name']] = $m;
  235. if ($m['issolution'] <> 1) {
  236. $localUninstallModules_noso[$m['name']] = $m;
  237. $localUninstallModules_title[$m['name']] = $m['title'];
  238. }
  239. $moduleids[] = $manifest['application']['identifie'];
  240. }
  241. }
  242. }
  243. }
  244. }
  245. $prepare_module = json_encode(array_keys($localUninstallModules_noso));
  246. $prepare_module_title = json_encode($localUninstallModules_title);
  247. template('extension/module');
  248. }
  249. if($do == 'permission') {
  250. load()->model('module');
  251. $id = $_GPC['id'];
  252. $module = pdo_fetch("SELECT mid, name FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $id));
  253. if(!empty($module[''])) {}
  254. $isinstall = false;
  255. $from = '';
  256. cache_load('modules');
  257. if(!empty($module)) {
  258. $module = $_W['modules'][$module['name']];
  259. if (empty($module)) {
  260. $data = pdo_getall('modules');
  261. $update = array();
  262. foreach ($data as &$mod) {
  263. unset($mod['permission']);
  264. $mod['subscribes'] = unserialize($mod['subscribes']);
  265. $mod['handles'] = unserialize($mod['handles']);
  266. $update[$mod['name']] = $mod;
  267. }
  268. cache_write('modules', $update);
  269. cache_load('modules');
  270. $module = $_W['modules'][$module['name']];
  271. }
  272. $bindings = pdo_fetchall('SELECT * FROM ' . tablename('modules_bindings') . ' WHERE `module`=:module', array(':module' => $id));
  273. if(!empty($bindings)) {
  274. foreach($bindings as $entry) {
  275. $module[$entry['entry']][] = array_elements(array('title', 'do', 'direct', 'state'), $entry);
  276. }
  277. }
  278. $manifest = ext_module_manifest($module['name']);
  279. if(is_array($manifest) && ver_compare($module['version'], $manifest['application']['version']) == -1) {
  280. $module['upgrade'] = 1;
  281. }
  282. $isinstall = true;
  283. $from = 'installed';
  284. if(in_array($module['name'], $sysmodules)) {
  285. $issystem = 1;
  286. }
  287. $manifest = ext_module_manifest($id);
  288. $from = 'local';
  289. }
  290. if (empty($module)) {
  291. message('你访问的模块不存在. 或许你愿意去微擎云服务平台看看. ', 'http://v2.addons.we7.cc/web/index.php?keyword=' . $_GPC['title']);
  292. }
  293. $module['isinstall'] = $isinstall;
  294. $module['from'] = $from;
  295. $mtypes = ext_module_msg_types();
  296. $modtypes = module_types();
  297. $issystem = $module['issystem'];
  298. if($issystem) {
  299. $path = '../framework/builtin/' . $module['name'];
  300. } else {
  301. $path = '../addons/' . $module['name'];
  302. }
  303. $cion = $path . '/icon-custom.jpg';
  304. $preview = $path . '/preview-custom.jpg';
  305. if(!file_exists($cion)) {
  306. $cion = $path . '/icon.jpg';
  307. }
  308. if(!file_exists($preview)) {
  309. $preview = $path . '/preview.jpg';
  310. }
  311. template('extension/permission');
  312. }
  313. if($do == 'install') {
  314. if (empty($_W['isfounder'])) {
  315. message('您没有安装模块的权限', '', 'error');
  316. }
  317. $modulename = $_GPC['m'];
  318. if (pdo_fetchcolumn("SELECT mid FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $modulename))) {
  319. message('模块已经安装或是唯一标识已存在!', '', 'error');
  320. }
  321. $manifest = ext_module_manifest($modulename);
  322. if (!empty($manifest)) {
  323. $r = cloud_m_prepare($modulename);
  324. if (is_error($r)) {
  325. message($r['message'], url('extension/module/prepared'), 'error');
  326. }
  327. }
  328. if (empty($manifest)) {
  329. $r = cloud_prepare();
  330. if (is_error($r)) {
  331. message($r['message'], url('cloud/profile'), 'error');
  332. }
  333. $info = cloud_m_info($modulename);
  334. if (!is_error($info)) {
  335. if (empty($_GPC['flag'])) {
  336. header('location: ' . url('cloud/process', array('m' => $modulename)));
  337. exit;
  338. } else {
  339. define('ONLINE_MODULE', true);
  340. $packet = cloud_m_build($modulename);
  341. $manifest = ext_module_manifest_parse($packet['manifest']);
  342. }
  343. } else {
  344. message($info['message'], '', 'error');
  345. }
  346. }
  347. if (empty($manifest)) {
  348. message('模块安装配置文件不存在或是格式不正确,请刷新重试!', '', 'error');
  349. }
  350. manifest_check($modulename, $manifest);
  351. $modulepath = IA_ROOT . '/addons/' . $modulename . '/';
  352. if (!file_exists($modulepath . 'processor.php') && !file_exists($modulepath . 'module.php') && !file_exists($modulepath . 'receiver.php') && !file_exists($modulepath . 'site.php')) {
  353. message('模块处理文件 site.php, processor.php, module.php, receiver.php 一个都不存在 !', '', 'error');
  354. }
  355. $module = ext_module_convert($manifest);
  356. $groups = uni_groups();
  357. if (!$_W['ispost'] || empty($_GPC['flag'])) {
  358. template('extension/select-groups');
  359. exit;
  360. }
  361. $post_groups = $_GPC['group'];
  362. ext_module_clean($modulename);
  363. $bindings = array_elements(array_keys($points), $module, false);
  364. foreach ($points as $p => $row) {
  365. unset($module[$p]);
  366. if (is_array($bindings[$p]) && !empty($bindings[$p])) {
  367. foreach ($bindings[$p] as $entry) {
  368. $entry['module'] = $manifest['application']['identifie'];
  369. $entry['entry'] = $p;
  370. pdo_insert('modules_bindings', $entry);
  371. }
  372. }
  373. }
  374. $module['permissions'] = iserializer($module['permissions']);
  375. if (!empty($info['version']['cloud_setting'])) {
  376. $module['settings'] = 2;
  377. }
  378. if ($modulename == 'we7_coupon') {
  379. $module['issystem'] = 1;
  380. $module['settings'] = 2;
  381. }
  382. if (pdo_insert('modules', $module)) {
  383. if (strexists($manifest['install'], '.php')) {
  384. if (file_exists($modulepath . $manifest['install'])) {
  385. include_once $modulepath . $manifest['install'];
  386. }
  387. } else {
  388. pdo_run($manifest['install']);
  389. }
  390. update_handle($module['name']);
  391. if (defined('ONLINE_MODULE')) {
  392. ext_module_script_clean($module['name'], $manifest);
  393. }
  394. if ($_GPC['flag'] && !empty($post_groups) && $module['name']) {
  395. foreach ($post_groups as $post_group) {
  396. $item = pdo_fetch("SELECT id,name,modules FROM " . tablename('uni_group') . " WHERE id = :id", array(':id' => intval($post_group)));
  397. if (empty($item)) {
  398. continue;
  399. }
  400. $item['modules'] = iunserializer($item['modules']);
  401. if (in_array($module['name'], $item['modules'])) {
  402. continue;
  403. }
  404. $item['modules'][] = $module['name'];
  405. $item['modules'] = iserializer($item['modules']);
  406. pdo_update('uni_group', $item, array('id' => $post_group));
  407. }
  408. }
  409. $module_subscribe_success = true;
  410. if (!empty($module['subscribes'])) {
  411. $subscribes = iunserializer($module['subscribes']);
  412. if (!empty($subscribes)) {
  413. $module_subscribe_success = ext_check_module_subscribe($module['name']);
  414. }
  415. }
  416. load()->model('module');
  417. module_build_privileges();
  418. cache_build_module_subscribe_type();
  419. cache_build_account_modules();
  420. if (empty($module_subscribe_success)) {
  421. message('模块安装成功, 请按照【公众号服务套餐】【用户组】来分配权限!模块订阅消息有错误,系统已禁用该模块的订阅消息,详细信息请查看 <div><a class="btn btn-primary" style="width:80px;" href="' . url('extension/subscribe/subscribe') . '">订阅管理</a> &nbsp;&nbsp;<a class="btn btn-default" href="' . url('extension/module') . '">返回模块列表</a></div>', '', 'tips');
  422. } else {
  423. message('模块安装成功, 请按照【公众号服务套餐】【用户组】来分配权限!', url('extension/module'), 'success');
  424. }
  425. } else {
  426. message('模块安装失败, 请联系模块开发者!');
  427. }
  428. }
  429. if ($do == 'uninstall') {
  430. if (empty($_W['isfounder'])) {
  431. message('您没有卸载模块的权限', '', 'error');
  432. }
  433. $id = $_GPC['id'];
  434. $module = pdo_fetch("SELECT `name`, `isrulefields`, `issystem`, `version` FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $id));
  435. if (empty($module)) {
  436. message('模块已经被卸载或是不存在!', '', 'error');
  437. }
  438. if (!empty($module['issystem'])) {
  439. message('系统模块不能卸载!', '', 'error');
  440. }
  441. if ($module['isrulefields'] && !isset($_GPC['confirm'])) {
  442. message('卸载模块时同时删除规则数据吗, 删除规则数据将同时删除相关规则的统计分析数据?<div><a class="btn btn-primary" style="width:80px;" href="' . url('extension/module/uninstall', array('id' => $_GPC['id'], 'confirm' => 1)) . '">是</a> &nbsp;&nbsp;<a class="btn btn-default" style="width:80px;" href="' . url('extension/module/uninstall', array('id' => $_GPC['id'], 'confirm' => 0)) . '">否</a></div>', '', 'tips');
  443. } else {
  444. $modulepath = IA_ROOT . '/addons/' . $id . '/';
  445. $manifest = ext_module_manifest($module['name']);
  446. if (empty($manifest)) {
  447. $r = cloud_prepare();
  448. if (is_error($r)) {
  449. message($r['message'], url('cloud/profile'), 'error');
  450. }
  451. $packet = cloud_m_build($module['name'], $do);
  452. if ($packet['sql']) {
  453. pdo_run(base64_decode($packet['sql']));
  454. } elseif ($packet['script']) {
  455. $uninstall_file = $modulepath . TIMESTAMP . '.php';
  456. file_put_contents($uninstall_file, base64_decode($packet['script']));
  457. require($uninstall_file);
  458. unlink($uninstall_file);
  459. }
  460. } elseif (!empty($manifest['uninstall'])) {
  461. if (strexists($manifest['uninstall'], '.php')) {
  462. if (file_exists($modulepath . $manifest['uninstall'])) {
  463. require($modulepath . $manifest['uninstall']);
  464. }
  465. } else {
  466. pdo_run($manifest['uninstall']);
  467. }
  468. }
  469. ext_module_clean($id, $_GPC['confirm'] == '1');
  470. cache_build_account_modules();
  471. cache_build_module_subscribe_type();
  472. pdo_insert('modules_recycle', array('modulename' => $module['name']));
  473. message('模块已放入回收站!', url('extension/module'), 'success');
  474. }
  475. }
  476. if($do == 'upgrade') {
  477. $id = $_GPC['m'];
  478. $module = pdo_fetch("SELECT mid, name, version FROM " . tablename('modules') . " WHERE name = :name", array(':name' => $id));
  479. if (empty($module)) {
  480. message('模块已经被卸载或是不存在!', '', 'error');
  481. }
  482. $type = $_GPC['type'];
  483. $modulepath = IA_ROOT . '/addons/' . $id . '/';
  484. if ($type == 'getinfo') {
  485. $manifest = '';
  486. } else {
  487. $manifest = ext_module_manifest($module['name']);
  488. }
  489. if (empty($manifest)) {
  490. $r = cloud_prepare();
  491. if (is_error($r)) {
  492. message($r['message'], url('cloud/profile'), 'error');
  493. }
  494. $info = cloud_m_upgradeinfo($id);
  495. if ($_W['isajax'] && $type == 'getinfo') {
  496. if ($info['free']) {
  497. foreach ($info['branches'] as &$branch) {
  498. $branch['upgrade_price'] = 0;
  499. }
  500. }
  501. message($info, '', 'ajax');
  502. }
  503. if (is_error($info)) {
  504. message($info['message'], referer(), 'error');
  505. }
  506. if (!is_error($info)) {
  507. if (empty($_GPC['flag'])) {
  508. $site_branch_displayorder = $info['branches'][$info['version']['branch_id']]['displayorder'];
  509. $upgrade_branch_displayorder = $info['branches'][intval($_GPC['branch'])]['displayorder'];
  510. if (($upgrade_branch_displayorder > $site_branch_displayorder) || ($site_branch_displayorder == $upgrade_branch_displayorder && intval($_GPC['branch']) > $info['version']['branch_id'])) {
  511. header('location: ' . url('cloud/redirect/buybranch', array('m' => $id, 'branch' => intval($_GPC['branch']), 'is_upgrade' => 1)));
  512. exit;
  513. }
  514. header('location: ' . url('cloud/process', array('m' => $id, 'is_upgrade' => 1)));
  515. exit;
  516. } else {
  517. define('ONLINE_MODULE', true);
  518. $packet = cloud_m_build($id);
  519. $manifest = ext_module_manifest_parse($packet['manifest']);
  520. }
  521. }
  522. }
  523. if (empty($manifest)) {
  524. message('模块安装配置文件不存在或是格式不正确!', '', 'error');
  525. }
  526. manifest_check($id, $manifest);
  527. if (!file_exists($modulepath . 'processor.php') && !file_exists($modulepath . 'module.php') && !file_exists($modulepath . 'receiver.php') && !file_exists($modulepath . 'site.php')) {
  528. message('模块处理文件 site.php, processor.php, module.php, receiver.php 一个都不存在 !', '', 'error');
  529. }
  530. $module = ext_module_convert($manifest);
  531. unset($module['name']);
  532. unset($module['id']);
  533. $bindings = array_elements(array_keys($points), $module, false);
  534. foreach ($points as $p => $row) {
  535. unset($module[$p]);
  536. if (is_array($bindings[$p]) && !empty($bindings[$p])) {
  537. foreach ($bindings[$p] as $entry) {
  538. $entry['module'] = $manifest['application']['identifie'];
  539. $entry['entry'] = $p;
  540. if ($entry['title'] && $entry['do']) {
  541. $delete_do[] = $entry['do'];
  542. $delete_title[] = $entry['title'];
  543. $sql = 'SELECT * FROM ' . tablename('modules_bindings') . ' WHERE `module`=:module AND `entry`=:entry AND `title`=:title AND `do`=:do';
  544. $pars = array();
  545. $pars[':module'] = $manifest['application']['identifie'];
  546. $pars[':entry'] = $p;
  547. $pars[':title'] = $entry['title'];
  548. $pars[':do'] = $entry['do'];
  549. $rec = pdo_fetch($sql, $pars);
  550. if (!empty($rec)) {
  551. pdo_update('modules_bindings', $entry, array('eid' => $rec['eid']));
  552. continue;
  553. }
  554. } elseif ($entry['call']) {
  555. $delete_call[] = $entry['call'];
  556. $sql = 'SELECT * FROM ' . tablename('modules_bindings') . ' WHERE `module`=:module AND `entry`=:entry AND `call`=:call';
  557. $pars = array();
  558. $pars[':module'] = $manifest['application']['identifie'];
  559. $pars[':entry'] = $p;
  560. $pars[':call'] = $entry['call'];
  561. $rec = pdo_fetch($sql, $pars);
  562. if (!empty($rec)) {
  563. pdo_update('modules_bindings', $entry, array('eid' => $rec['eid']));
  564. continue;
  565. }
  566. }
  567. pdo_insert('modules_bindings', $entry);
  568. }
  569. if (!empty($delete_do)) {
  570. pdo_query('DELETE FROM ' . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND `call` = '' AND do NOT IN ('" . implode("','", $delete_do) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $p));
  571. unset($delete_do);
  572. }
  573. if (!empty($delete_title)) {
  574. pdo_query('DELETE FROM ' . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND `call` = '' AND title NOT IN ('" . implode("','", $delete_title) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $p));
  575. unset($delete_title);
  576. }
  577. if (!empty($delete_call)) {
  578. pdo_query('DELETE FROM ' . tablename('modules_bindings') . " WHERE module = :module AND entry = :entry AND do = '' AND title = '' AND `call` NOT IN ('" . implode("','", $delete_call) . "')", array(':module' => $manifest['application']['identifie'], ':entry' => $p));
  579. unset($delete_call);
  580. }
  581. }
  582. }
  583. if (!empty($manifest['upgrade'])) {
  584. if (strexists($manifest['upgrade'], '.php')) {
  585. if (file_exists($modulepath . $manifest['upgrade'])) {
  586. include_once $modulepath . $manifest['upgrade'];
  587. }
  588. } else {
  589. pdo_run($manifest['upgrade']);
  590. }
  591. }
  592. if (defined('ONLINE_MODULE')) {
  593. ext_module_script_clean($id, $manifest);
  594. }
  595. $module['permissions'] = iserializer($module['permissions']);
  596. if (!empty($info['version']['cloud_setting'])) {
  597. $module['settings'] = 2;
  598. } else {
  599. if (empty($manifest['application']['setting'])) {
  600. $module['settings'] = 0;
  601. } else {
  602. $module['settings'] = 1;
  603. }
  604. }
  605. pdo_update('modules', $module, array('name' => $id));
  606. cache_build_account_modules();
  607. if (!empty($module['subscribes'])) {
  608. $module_subscribe_success = ext_check_module_subscribe($module['name']);
  609. }
  610. cache_delete('cloud:transtoken');
  611. if ($_GPC['flag'] == 1) {
  612. message('模块更新成功! <br> 由于数据库更新, 可能会产生多余的字段. 你可以按照需要删除.<div><a class="btn btn-primary" href="' . url('system/database/trim') . '">现在去删除</a>&nbsp;&nbsp;&nbsp;<a class="btn btn-default" href="' . url('extension/module/') . '">返回模块列表</a></div>', '', 'success');
  613. } else {
  614. message('模块更新成功!', referer(), 'success');
  615. }
  616. }
  617. if($do == 'designer') {
  618. if(empty($_W['isfounder'])) {
  619. message('您没有设计新模块的权限', '', 'error');
  620. }
  621. $_W['page']['title'] = '设计新模块 - 模块 - 扩展';
  622. load()->model('module');
  623. $available = array();
  624. $available['download'] = class_exists('ZipArchive');
  625. $available['create'] = @is_writable(IA_ROOT . '/addons');
  626. $mtypes = ext_module_msg_types();
  627. $modtypes = module_types();
  628. $versions = array();
  629. $versions[] = '0.6';
  630. $m = array();
  631. $m['platform'] = array();
  632. $m['platform']['subscribes'] = array();
  633. $m['platform']['handles'] = array();
  634. $m['site'] = array();
  635. $m['versions'] = array();
  636. if(checksubmit() && $available[$_GPC['method']]) {
  637. $m['application']['name'] = trim($_GPC['application']['name']);
  638. if(empty($m['application']['name']) || preg_match('/\*\/|\/\*|eval|\$\_/i', $m['application']['name'])) {
  639. message('请输入有效的模块名称. ');
  640. }
  641. $m['application']['identifie'] = trim($_GPC['application']['identifie']);
  642. if(empty($m['application']['identifie']) || !preg_match('/^[a-z][a-z\d_]+$/i', $m['application']['identifie'])) {
  643. message('必须输入模块标识符(仅支持字母和数字, 且只能以字母开头). ');
  644. }
  645. $m['application']['version'] = trim($_GPC['application']['version']);
  646. if(empty($m['application']['version']) || !preg_match('/^[\d\.]+$/i', $m['application']['version'])) {
  647. message('必须输入模块版本号(仅支持数字和句点). ');
  648. }
  649. $m['application']['ability'] = trim($_GPC['application']['ability']);
  650. if(empty($m['application']['ability'])) {
  651. message('必须输入模块功能简述. ');
  652. }
  653. $m['application']['type'] = array_key_exists($_GPC['application']['type'], $modtypes) ? $_GPC['application']['type'] : 'other';
  654. $m['application']['description'] = trim($_GPC['application']['description']);
  655. $m['application']['author'] = trim($_GPC['application']['author']);
  656. if(preg_match('/\*\/|\/\*|eval|\$\_/i', $m['application']['author'])) {
  657. message('请输入有效的模块作者');
  658. }
  659. $m['application']['url'] = trim($_GPC['application']['url']);
  660. if(preg_match('/\*\/|\/\*|eval|\$\_/i', $m['application']['url'])) {
  661. message('请输入有效的模块发布页');
  662. }
  663. $m['application']['setting'] = $_GPC['application']['setting'] == 'true';
  664. if(is_array($_GPC['subscribes'])) {
  665. foreach($_GPC['subscribes'] as $s) {
  666. if(array_key_exists($s, $mtypes)) {
  667. $m['platform']['subscribes'][] = $s;
  668. }
  669. }
  670. }
  671. if(is_array($_GPC['handles'])) {
  672. foreach($_GPC['handles'] as $s) {
  673. if(array_key_exists($s, $mtypes) && $s != 'unsubscribe') {
  674. $m['platform']['handles'][] = $s;
  675. }
  676. }
  677. }
  678. $m['platform']['rule'] = $_GPC['platform']['rule'] == 'true';
  679. if($m['platform']['rule']) {
  680. if(!in_array('text', $m['platform']['handles'])) {
  681. $m['platform']['handles'][] = 'text';
  682. }
  683. }
  684. $m['platform']['card'] = $_GPC['platform']['card'] == 'true';
  685. $m['bindings'] = array();
  686. foreach($points as $p => $row) {
  687. if(!is_array($_GPC['bindings'][$p]['titles'])) {
  688. continue;
  689. }
  690. foreach($_GPC['bindings'][$p]['titles'] as $key => $t) {
  691. $entry = array();
  692. $entry['title'] = trim($t);
  693. $entry['do'] = $_GPC['bindings'][$p]['dos'][$key];
  694. $entry['state'] = $_GPC['bindings'][$p]['state'][$key];
  695. $entry['direct'] = $_GPC['bindings'][$p]['direct'][$key] == 'true';
  696. if(!empty($entry['title']) && preg_match('/^[a-z\d]+$/i', $entry['do'])) {
  697. $m['bindings'][$p][] = $entry;
  698. }
  699. }
  700. }
  701. $permission = trim($_GPC['permission']);
  702. if(!empty($permission)) {
  703. $permission = str_replace(array(':'), array(':'), $permission);
  704. $permission = explode("\n", $permission);
  705. $arr = array();
  706. foreach($permission as $li) {
  707. $li = trim($li);
  708. $li = explode(':', $li);
  709. if(!empty($li[0]) && !empty($li[1])) {
  710. $arr[] = array('title' => $li[0], 'permission' => $li[1]);
  711. }
  712. }
  713. $m['permission'] = $arr;
  714. }
  715. if(is_array($_GPC['versions'])) {
  716. foreach($_GPC['versions'] as $ver) {
  717. if(in_array($ver, $versions)) {
  718. $m['versions'][] = $ver;
  719. }
  720. }
  721. }
  722. $m['install'] = trim($_GPC['install']);
  723. $m['uninstall'] = trim($_GPC['uninstall']);
  724. $m['upgrade'] = trim($_GPC['upgrade']);
  725. if($_FILES['icon'] && $_FILES['icon']['error'] == '0' && !empty($_FILES['icon']['tmp_name'])) {
  726. $m['icon'] = $_FILES['icon']['tmp_name'];
  727. }
  728. if($_FILES['preview'] && $_FILES['preview']['error'] == '0' && !empty($_FILES['preview']['tmp_name'])) {
  729. $m['preview'] = $_FILES['preview']['tmp_name'];
  730. }
  731. $manifest = manifest($m);
  732. $mDefine = define_module($m);
  733. $pDefine = define_processor($m);
  734. $rDefine = define_receiver($m);
  735. $sDefine = define_site($m);
  736. $ident = strtolower($m['application']['identifie']);
  737. if ($_GPC['method'] == 'create') {
  738. load()->func('file');
  739. $mRoot = IA_ROOT . "/addons/{$ident}";
  740. if(file_exists($mRoot)) {
  741. message("目标位置 {$mRoot} 已存在, 请更换标识或删除现有内容. ");
  742. }
  743. mkdirs($mRoot);
  744. f_write("{$mRoot}/manifest.xml", $manifest);
  745. if($mDefine) {
  746. f_write("{$mRoot}/module.php", $mDefine);
  747. }
  748. if($pDefine) {
  749. f_write("{$mRoot}/processor.php", $pDefine);
  750. }
  751. if($rDefine) {
  752. f_write("{$mRoot}/receiver.php", $rDefine);
  753. }
  754. if($sDefine) {
  755. f_write("{$mRoot}/site.php", $sDefine);
  756. }
  757. mkdirs("{$mRoot}/template");
  758. if($m['application']['setting']) {
  759. f_write("{$mRoot}/template/setting.html", "{template 'common/header'}\r\n这里定义页面内容\r\n{template 'common/footer'}");
  760. }
  761. if($m['icon']) {
  762. file_move($m['icon'], "{$mRoot}/icon.jpg");
  763. }
  764. if($m['preview']) {
  765. file_move($m['preview'], "{$mRoot}/preview.jpg");
  766. }
  767. message("生成成功. 请访问 {$mRoot} 继续实现你的模块.", 'refresh');
  768. die;
  769. }
  770. if($_GPC['method'] == 'download') {
  771. $fname = IA_ROOT . "/data/tmp.zip";
  772. $zip = new ZipArchive();
  773. $zip->open($fname, ZipArchive::CREATE);
  774. $zip->addFromString('manifest.xml', $manifest);
  775. if($mDefine) {
  776. $zip->addFromString('module.php', $mDefine);
  777. }
  778. if($pDefine) {
  779. $zip->addFromString('processor.php', $pDefine);
  780. }
  781. if($rDefine) {
  782. $zip->addFromString('receiver.php', $rDefine);
  783. }
  784. if($sDefine) {
  785. $zip->addFromString('site.php', $sDefine);
  786. }
  787. $zip->addEmptyDir('template');
  788. if($m['application']['setting']) {
  789. $zip->addFromString("template/setting.html", "{template 'common/header'}\r\n这里定义页面内容\r\n{template 'common/footer'}");
  790. }
  791. if($m['icon']) {
  792. $zip->addFile($m['icon'], 'icon.jpg');
  793. }
  794. if($m['preview']) {
  795. $zip->addFile($m['preview'], 'preview.jpg');
  796. }
  797. $zip->close();
  798. header('content-type: application/zip');
  799. header('content-disposition: attachment; filename="' . $ident . '.zip"');
  800. readfile($fname);
  801. @unlink($m['icon']);
  802. @unlink($m['preview']);
  803. @unlink($fname);
  804. }
  805. }
  806. template('extension/designer');
  807. }
  808. function manifest_check($id, $m) {
  809. if(is_string($m)) {
  810. message('模块配置项定义错误, 具体错误内容为: <br />' . $m);
  811. }
  812. if(empty($m['application']['name'])) {
  813. message('模块名称未定义. ');
  814. }
  815. if(empty($m['application']['identifie']) || !preg_match('/^[a-z][a-z\d_]+$/i', $m['application']['identifie'])) {
  816. message('模块标识符未定义或格式错误(仅支持字母和数字, 且只能以字母开头). ');
  817. }
  818. if(strtolower($id) != strtolower($m['application']['identifie'])) {
  819. message('模块名称定义与模块路径名称定义不匹配. ');
  820. }
  821. if(empty($m['application']['version']) || !preg_match('/^[\d\.]+$/i', $m['application']['version'])) {
  822. message('模块版本号未定义(仅支持数字和句点). ');
  823. }
  824. if(empty($m['application']['ability'])) {
  825. message('模块功能简述未定义. ');
  826. }
  827. if($m['platform']['isrulefields'] && !in_array('text', $m['platform']['handles'])) {
  828. message('模块功能定义错误, 嵌入规则必须要能够处理文本类型消息. ');
  829. }
  830. if((!empty($m['cover']) || !empty($m['rule'])) && !$m['platform']['isrulefields']) {
  831. message('模块功能定义错误, 存在封面或规则功能入口绑定时, 必须要嵌入规则. ');
  832. }
  833. global $points;
  834. foreach($points as $p => $row) {
  835. if(is_array($m[$p])) {
  836. foreach($m[$p] as $o) {
  837. if(trim($o['title']) == '' || !preg_match('/^[a-z\d]+$/i', $o['do']) && empty($o['call'])) {
  838. message($row['title'] . ' 扩展项功能入口定义错误, (操作标题[title], 入口方法[do])格式不正确.');
  839. }
  840. }
  841. }
  842. }
  843. if(is_array($m['permissions']) && !empty($m['permissions'])) {
  844. foreach($m['permissions'] as $permission) {
  845. if(trim($permission['title']) == '' || !preg_match('/^[a-z\d_]+$/i', $permission['permission'])) {
  846. message("名称为: {$permission['title']} 的权限标识格式不正确,请检查标识名称或标识格式是否正确");
  847. }
  848. }
  849. }
  850. if(!is_array($m['versions'])) {
  851. message('兼容版本格式错误. ');
  852. }
  853. }
  854. function manifest($m) {
  855. $versions = implode(',', $m['versions']);
  856. $setting = $m['application']['setting'] ? 'true' : 'false';
  857. $subscribes = '';
  858. foreach($m['platform']['subscribes'] as $s) {
  859. $subscribes .= "\r\n\t\t\t<message type=\"{$s}\" />";
  860. }
  861. $handles = '';
  862. foreach($m['platform']['handles'] as $h) {
  863. $handles .= "\r\n\t\t\t<message type=\"{$h}\" />";
  864. }
  865. $rule = $m['platform']['rule'] ? 'true' : 'false';
  866. $card = $m['platform']['card'] ? 'true' : 'false';
  867. $bindings = '';
  868. global $points;
  869. foreach($points as $p => $row) {
  870. if(is_array($m['bindings'][$p]) && !empty($m['bindings'][$p])) {
  871. $piece = "\r\n\t\t<{$p}>";
  872. foreach($m['bindings'][$p] as $entry) {
  873. $direct = $entry['direct'] ? 'true' : 'false';
  874. $piece .= "\r\n\t\t\t<entry title=\"{$entry['title']}\" do=\"{$entry['do']}\" state=\"{$entry['state']}\" direct=\"{$direct}\" />";
  875. }
  876. $piece .= "\r\n\t\t</{$p}>";
  877. $bindings .= $piece;
  878. }
  879. }
  880. if(is_array($m['permission']) && !empty($m['permission'])) {
  881. $permissions = '';
  882. foreach($m['permission'] as $entry) {
  883. $piece .= "\r\n\t\t\t<entry title=\"{$entry['title']}\" do=\"{$entry['permission']}\" />";
  884. }
  885. $permissions .= $piece;
  886. }
  887. $tpl = <<<TPL
  888. <?xml version="1.0" encoding="utf-8"?>
  889. <manifest xmlns="http://www.we7.cc" versionCode="{$versions}">
  890. <application setting="{$setting}">
  891. <name><![CDATA[{$m['application']['name']}]]></name>
  892. <identifie><![CDATA[{$m['application']['identifie']}]]></identifie>
  893. <version><![CDATA[{$m['application']['version']}]]></version>
  894. <type><![CDATA[{$m['application']['type']}]]></type>
  895. <ability><![CDATA[{$m['application']['ability']}]]></ability>
  896. <description><![CDATA[{$m['application']['description']}]]></description>
  897. <author><![CDATA[{$m['application']['author']}]]></author>
  898. <url><![CDATA[{$m['application']['url']}]]></url>
  899. </application>
  900. <platform>
  901. <subscribes>{$subscribes}
  902. </subscribes>
  903. <handles>{$handles}
  904. </handles>
  905. <rule embed="{$rule}" />
  906. <card embed="{$card}" />
  907. </platform>
  908. <bindings>{$bindings}
  909. </bindings>
  910. <permissions>{$permissions}
  911. </permissions>
  912. <install><![CDATA[{$m['install']}]]></install>
  913. <uninstall><![CDATA[{$m['uninstall']}]]></uninstall>
  914. <upgrade><![CDATA[{$m['upgrade']}]]></upgrade>
  915. </manifest>
  916. TPL;
  917. return ltrim($tpl);
  918. }
  919. function define_module($m) {
  920. $name = ucfirst($m['application']['identifie']);
  921. $rule = '';
  922. if($m['platform']['rule']) {
  923. $rule = <<<TPL
  924. public function fieldsFormDisplay(\$rid = 0) {
  925. //要嵌入规则编辑页的自定义内容,这里 \$rid 为对应的规则编号,新增时为 0
  926. }
  927. public function fieldsFormValidate(\$rid = 0) {
  928. //规则编辑保存时,要进行的数据验证,返回空串表示验证无误,返回其他字符串将呈现为错误提示。这里 \$rid 为对应的规则编号,新增时为 0
  929. return '';
  930. }
  931. public function fieldsFormSubmit(\$rid) {
  932. //规则验证无误保存入库时执行,这里应该进行自定义字段的保存。这里 \$rid 为对应的规则编号
  933. }
  934. public function ruleDeleted(\$rid) {
  935. //删除规则时调用,这里 \$rid 为对应的规则编号
  936. }
  937. TPL;
  938. }
  939. $setting = '';
  940. if($m['application']['setting']) {
  941. $setting = <<<TPL
  942. public function settingsDisplay(\$settings) {
  943. global \$_W, \$_GPC;
  944. //点击模块设置时将调用此方法呈现模块设置页面,\$settings 为模块设置参数, 结构为数组。这个参数系统针对不同公众账号独立保存。
  945. //在此呈现页面中自行处理post请求并保存设置参数(通过使用\$this->saveSettings()来实现)
  946. if(checksubmit()) {
  947. //字段验证, 并获得正确的数据\$dat
  948. \$this->saveSettings(\$dat);
  949. }
  950. //这里来展示设置项表单
  951. include \$this->template('setting');
  952. }
  953. TPL;
  954. }
  955. $tpl = <<<TPL
  956. <?php
  957. /**
  958. * {$m['application']['name']}模块定义
  959. *
  960. * @author {$m['application']['author']}
  961. * @url {$m['application']['url']}
  962. */
  963. defined('IN_IA') or exit('Access Denied');
  964. class {$name}Module extends WeModule {
  965. {$rule}
  966. {$setting}
  967. }
  968. TPL;
  969. return ltrim($tpl);
  970. }
  971. function define_processor($m) {
  972. $name = ucfirst($m['application']['identifie']);
  973. $tpl = '';
  974. if($m['platform']['handles']) {
  975. $tpl = <<<TPL
  976. <?php
  977. /**
  978. * {$m['application']['name']}模块处理程序
  979. *
  980. * @author {$m['application']['author']}
  981. * @url {$m['application']['url']}
  982. */
  983. defined('IN_IA') or exit('Access Denied');
  984. class {$name}ModuleProcessor extends WeModuleProcessor {
  985. public function respond() {
  986. \$content = \$this->message['content'];
  987. //这里定义此模块进行消息处理时的具体过程, 请查看微擎文档来编写你的代码
  988. }
  989. }
  990. TPL;
  991. }
  992. return ltrim($tpl);
  993. }
  994. function define_receiver($m) {
  995. $name = ucfirst($m['application']['identifie']);
  996. $tpl = '';
  997. if($m['platform']['subscribes']) {
  998. $tpl = <<<TPL
  999. <?php
  1000. /**
  1001. * {$m['application']['name']}模块订阅器
  1002. *
  1003. * @author {$m['application']['author']}
  1004. * @url {$m['application']['url']}
  1005. */
  1006. defined('IN_IA') or exit('Access Denied');
  1007. class {$name}ModuleReceiver extends WeModuleReceiver {
  1008. public function receive() {
  1009. \$type = \$this->message['type'];
  1010. //这里定义此模块进行消息订阅时的, 消息到达以后的具体处理过程, 请查看微擎文档来编写你的代码
  1011. }
  1012. }
  1013. TPL;
  1014. }
  1015. return ltrim($tpl);
  1016. }
  1017. function define_site($m) {
  1018. global $points;
  1019. $name = ucfirst($m['application']['identifie']);
  1020. $tpl = '';
  1021. $dos = '';
  1022. if(is_array($m['bindings']) && !empty($m['bindings'])) {
  1023. $webdos = array();
  1024. $appdos = array();
  1025. foreach($points as $p => $row) {
  1026. if(!empty($m['bindings'][$p]) && in_array($p, array('rule', 'menu'))) {
  1027. foreach($m['bindings'][$p] as $opt) {
  1028. if(in_array($opt['do'], $webdos)){
  1029. continue;
  1030. }
  1031. $webdos[] = $opt['do'];
  1032. $dName = ucfirst($opt['do']);
  1033. $dos .= <<<TPL
  1034. public function doWeb{$dName}() {
  1035. //这个操作被定义用来呈现 {$row['title']}
  1036. }
  1037. TPL;
  1038. }
  1039. }
  1040. if(!empty($m['bindings'][$p]) && in_array($p, array('cover', 'home', 'profile', 'shortcut'))) {
  1041. foreach($m['bindings'][$p] as $opt) {
  1042. if(in_array($opt['do'], $appdos)){
  1043. continue;
  1044. }
  1045. $appdos[] = $opt['do'];
  1046. $dName = ucfirst($opt['do']);
  1047. $dos .= <<<TPL
  1048. public function doMobile{$dName}() {
  1049. //这个操作被定义用来呈现 {$row['title']}
  1050. }
  1051. TPL;
  1052. }
  1053. }
  1054. }
  1055. $tpl = <<<TPL
  1056. <?php
  1057. /**
  1058. * {$m['application']['name']}模块微站定义
  1059. *
  1060. * @author {$m['application']['author']}
  1061. * @url {$m['application']['url']}
  1062. */
  1063. defined('IN_IA') or exit('Access Denied');
  1064. class {$name}ModuleSite extends WeModuleSite {
  1065. {$dos}
  1066. }
  1067. TPL;
  1068. }
  1069. return ltrim($tpl);
  1070. }
  1071. function f_write($filename, $data) {
  1072. global $_W;
  1073. mkdirs(dirname($filename));
  1074. file_put_contents($filename, $data);
  1075. @chmod($filename, $_W['config']['setting']['filemode']);
  1076. return is_file($filename);
  1077. }
  1078. function update_handle($module = '') {
  1079. $isupdate = 0;
  1080. if(file_exists(IA_ROOT . '/data/modules_log.php')) {
  1081. $isupdate = 1;
  1082. }
  1083. if(!$isupdate || empty($module)) {
  1084. return true;
  1085. } else {
  1086. @require IA_ROOT . '/data/modules_log.php';
  1087. if(!empty($module_log)) {
  1088. if(isset($module_log[$module])) {
  1089. pdo_update('modules', array('version' => $module_log[$module]), array('name' => $module));
  1090. unset($module_log[$module]);
  1091. }
  1092. if(empty($module_log)) {
  1093. @unlink(IA_ROOT . '/data/modules_log.php');
  1094. } else {
  1095. $content_update = "<?php\r\n";
  1096. $content_update .= "\$module_log = " . var_export($module_log, true) . ";\r\n";
  1097. $content_update .= "?>";
  1098. file_put_contents(IA_ROOT . '/data/modules_log.php', $content_update);
  1099. }
  1100. } else {
  1101. @unlink(IA_ROOT . '/data/modules_log.php');
  1102. }
  1103. return true;
  1104. }
  1105. }