module.ctrl.php 40 KB

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