人人商城

template.ctrl.php 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. $dos = array('installed', 'not_install', 'uninstall', 'install', 'upgrade', 'check_upgrade', 'get_upgrade_info');
  10. $do = in_array($do, $dos) ? $do : 'installed';
  11. if ($do == 'get_upgrade_info') {
  12. $template_name = $_GPC['name'];
  13. if (!empty($template_name)) {
  14. $template_info = pdo_get('site_templates', array('name' => $template_name));
  15. if (!empty($template_info)) {
  16. $cloud_t_upgrade_info = cloud_t_upgradeinfo($template_name); if (is_error($cloud_t_upgrade_info)) {
  17. iajax(1, $cloud_t_upgrade_info['message'], '');
  18. }
  19. $template_upgrade_info = array(
  20. 'name' => $cloud_t_upgrade_info['name'],
  21. 'title' => $template_info['title'],
  22. 'version' => $cloud_t_upgrade_info['version'],
  23. 'branches' => $cloud_t_upgrade_info['branches'],
  24. 'site_branch' => $cloud_t_upgrade_info['branches'][$cloud_t_upgrade_info['version']['branch_id']],
  25. );
  26. iajax(0, $template_upgrade_info, '');
  27. } else {
  28. iajax(1, '模板不存在', '');
  29. }
  30. }
  31. }
  32. if ($do == 'check_upgrade') {
  33. $template_list = $_GPC['template'];
  34. if (empty($template_list) || !is_array($template_list)) {
  35. iajax(1, '');
  36. }
  37. $cloud_template_list = cloud_t_query();
  38. if (is_error($cloud_template_list)) {
  39. $cloud_template_list = array();
  40. }
  41. foreach ($template_list as &$template) {
  42. $manifest = ext_template_manifest($template['name'], false);
  43. if (!empty($manifest)&& is_array($manifest)) {
  44. if (version_compare($template['version'], $manifest['application']['version']) == '-1') {
  45. $template['upgrade'] = 1;
  46. } else {
  47. $template['upgrade'] = 0;
  48. }
  49. $template['from'] = 'local';
  50. } else {
  51. if (in_array($template['name'], array_keys($cloud_template_list))) {
  52. $template['from'] = 'cloud';
  53. $site_branch = $cloud_template_list[$template['name']]['branch']; $cloud_branch_version = $cloud_template_list[$template['name']]['branches'][$site_branch]['version']; $best_branch = current($cloud_template_list[$template['name']]['branches']);
  54. if (version_compare($template['version'], $cloud_branch_version) == -1 || ($cloud_template_list[$template['name']]['branch'] < $best_branch['id'])) {
  55. $template['upgrade'] = 1;
  56. } else {
  57. $template['upgrade'] = 0;
  58. }
  59. }
  60. }
  61. }
  62. iajax(0, $template_list, '');
  63. }
  64. if ($do == 'installed') {
  65. $_W['page']['title'] = '已安装的微站风格 - 风格主题';
  66. $pindex = max(1, $_GPC['page']);
  67. $pagesize = 20;
  68. $param = empty($_GPC['type']) ? array() : array('type' => $_GPC['type']);
  69. if (!empty($_GPC['keyword'])) {
  70. $param['title LIKE'] = "%". trim($_GPC['keyword'])."%";
  71. }
  72. if (!$_W['isfounder'] || user_is_vice_founder()) {
  73. $group_info = pdo_get('users_founder_group', array('id' => $_W['user']['groupid']));
  74. $group_info['package'] = unserialize($group_info['package']);
  75. $uni_groups = pdo_getall('uni_group', array('uniacid' => 0, 'id' => $group_info['package']), array(), '', array('id DESC'));
  76. $templates = array();
  77. foreach ($uni_groups as $key => $group) {
  78. $ids = unserialize($group['templates']);
  79. foreach ($ids as $val) {
  80. $templates[] = $val;
  81. }
  82. }
  83. $param['id'] = $templates;
  84. }
  85. $template_list = pdo_getslice('site_templates', $param, array($pindex, $pagesize), $total, array(), 'name');
  86. $pager = pagination($total, $pindex, $pagesize);
  87. $temtypes = ext_template_type();
  88. }
  89. if ($do == 'not_install') {
  90. $_W['page']['title'] = '安装微站风格 - 风格主题 - 扩展';
  91. $installed_template = pdo_getall("site_templates", array(), array(), 'name');
  92. $uninstall_template = array();
  93. $cloud_template = cloud_t_query();
  94. if(!is_error($cloud_template)) {
  95. $cloudUninstallThemes = array();
  96. foreach($cloud_template as $name => $template_info) {
  97. if (empty($template_info) || !is_array($template_info)) {
  98. continue;
  99. }
  100. if(!in_array(strtolower($name), array_keys($installed_template))) {
  101. if (!empty($_GPC['keyword']) && !strexists($template_info['title'], trim($_GPC['keyword']))) {
  102. continue;
  103. }
  104. $uninstall_template[$name] = array(
  105. 'name' => $template_info['name'],
  106. 'title' => $template_info['title'],
  107. 'logo' => $template_info['logo'],
  108. 'from' => 'cloud'
  109. );
  110. }
  111. }
  112. }
  113. $path = IA_ROOT . '/app/themes';
  114. if (is_dir($path)) {
  115. $dir_tree = glob($path . '/*');
  116. if (!empty($dir_tree)) {
  117. foreach ($dir_tree as $modulepath) {
  118. $modulepath = str_replace(IA_ROOT. "/app/themes/", '', $modulepath);
  119. $manifest = ext_template_manifest($modulepath, false);
  120. if (!empty($_GPC['title']) && !strexists($manifest['title'], trim($_GPC['title']))) {
  121. continue;
  122. }
  123. if(!empty($manifest) && !in_array($manifest['name'], array_keys($installed_template))) {
  124. $uninstall_template[$manifest['name']] = $manifest;
  125. }
  126. }
  127. }
  128. }
  129. $total = count($uninstall_template);
  130. if (!empty($uninstall_template) && is_array($uninstall_template)) {
  131. $pindex = max(1, $_GPC['page']);
  132. $uninstall_template = array_slice($uninstall_template, ($pindex - 1) * 20, 20);
  133. }
  134. $pager = pagination($total, $pindex, 20);
  135. }
  136. if ($do == 'uninstall') {
  137. $template = pdo_getcolumn('site_templates', array('id' => intval($_GPC['id'])), 'name');
  138. if($template == 'default') {
  139. itoast('默认模板不能卸载', url('system/template/not_install'), 'error');
  140. }
  141. if (pdo_delete('site_templates', array('id' => intval($_GPC['id'])))) {
  142. pdo_delete('site_styles',array('templateid' => intval($_GPC['id'])));
  143. pdo_delete('site_styles_vars',array('templateid' => intval($_GPC['id'])));
  144. itoast('模板移除成功, 你可以重新安装, 或者直接移除文件来安全删除!', referer(), 'success');
  145. } else {
  146. itoast('模板移除失败, 请联系模板开发者!', url('system/template/not_install'), 'error');
  147. }
  148. }
  149. if ($do == 'install') {
  150. if(empty($_W['isfounder'])) {
  151. itoast('您没有安装模块的权限', url('system/template/not_install'), 'error');
  152. }
  153. $template_name = $_GPC['templateid'];
  154. if (pdo_get('site_templates', array('name' => $template_name))) {
  155. itoast('模板已经安装或是唯一标识已存在!', url('system/template/not_install'), 'error');
  156. }
  157. $manifest = ext_template_manifest($template_name, false);
  158. if (!empty($manifest)) {
  159. $prepare_result = cloud_t_prepare($template_name);
  160. if(is_error($prepare_result)) {
  161. itoast($prepare_result['message'], url('system/template/not_install'), 'error');
  162. }
  163. }
  164. if (empty($manifest)) {
  165. $cloud_result = cloud_prepare();
  166. if(is_error($cloud_result)) {
  167. itoast($cloud_result['message'], url('cloud/profile'), 'error');
  168. }
  169. $template_info = cloud_t_info($template_name);
  170. if (!is_error($template_info)) {
  171. if (empty($_GPC['flag'])) {
  172. header('location: ' . url('cloud/process', array('t' => $template_name)));
  173. exit;
  174. } else {
  175. $packet = cloud_t_build($template_name);
  176. $manifest = ext_template_manifest_parse($packet['manifest']);
  177. $manifest['version'] = $packet['version'];
  178. }
  179. } else {
  180. itoast($template_info['message'], '', 'error');
  181. }
  182. }
  183. unset($manifest['settings']);
  184. $module_group = uni_groups();
  185. if(!$_W['ispost'] || empty($_GPC['flag'])) {
  186. template('system/module-group');
  187. exit;
  188. }
  189. $post_groups = $_GPC['group'];
  190. $tid = intval($_GPC['tid']);
  191. $template_name = $_GPC['templateid'];
  192. if (empty($manifest)) {
  193. itoast('模板安装配置文件不存在或是格式不正确!', '', 'error');
  194. }
  195. if ($manifest['name'] != $template_name) {
  196. itoast('安装模板与文件标识不符,请重新安装', '', 'error');
  197. }
  198. if (pdo_get('site_templates', array('name' => $manifest['name']))) {
  199. itoast('模板已经安装或是唯一标识已存在!', url('system/template/not_install'), 'error');
  200. }
  201. if (pdo_insert('site_templates', $manifest)) {
  202. $tid = pdo_insertid();
  203. } else {
  204. itoast('模板安装失败, 请联系模板开发者!', '', 'error');
  205. }
  206. if($template_name && $post_groups) {
  207. if (!pdo_get('site_templates', array('id' => $tid))) {
  208. itoast('指定模板不存在!', '', 'error');
  209. }
  210. foreach($post_groups as $post_group) {
  211. $group = pdo_get('uni_group', array('id' => $post_group));
  212. if(empty($group)) {
  213. continue;
  214. }
  215. $group['templates'] = iunserializer($group['templates']);
  216. if(in_array($tid, $group['templates'])) {
  217. continue;
  218. }
  219. $group['templates'][] = $tid;
  220. $group['templates'] = iserializer($group['templates']);
  221. pdo_update('uni_group', $group, array('id' => $post_group));
  222. }
  223. }
  224. itoast('模板安装成功, 请按照【公众号服务套餐】【用户组】来分配权限!', url('system/template'), 'success');
  225. }
  226. if($do == 'upgrade') {
  227. $template_name = $_GPC['templateid'];
  228. $template = pdo_get("site_templates", array('name' => $template_name));
  229. if (empty($template)) {
  230. itoast('模板已经被卸载或是不存在!', url('system/template'), 'error');
  231. }
  232. if (!is_error($info)) {
  233. if (!empty($_GPC['flag'])) {
  234. $packet = cloud_t_build($template_name);
  235. $manifest = ext_template_manifest_parse($packet['manifest']);
  236. }
  237. }
  238. if (empty($manifest)) {
  239. itoast('模块安装配置文件不存在或是格式不正确!', '', 'error');
  240. }
  241. if(version_compare($template['version'], $packet['version']) != -1) {
  242. itoast('已安装的模板版本不低于要更新的版本, 操作无效.', '', 'error');
  243. }
  244. pdo_update('site_templates', array('version' => $packet['version']), array('id' => $template['id']));
  245. itoast('模板更新成功!', url('system/template'), 'success');
  246. }
  247. template('system/template');