style.ctrl.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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('module');
  9. load()->func('file');
  10. $dos = array('default', 'designer', 'module', 'template', 'copy', 'build', 'del');
  11. $do = in_array($do, $dos) ? $do : 'template';
  12. permission_check_account_user('platform_site_style');
  13. $site_multi_table = table('site_multi');
  14. $site_styles_table = table('site_styles');
  15. $site_styles_vars_table = table('site_styles_vars');
  16. $site_templates_table = table('site_templates');
  17. if ($do == 'template') {
  18. $setting = uni_setting($_W['uniacid'], array('default_site'));
  19. $site_multi_info = $site_multi_table->getById($setting['default_site']);
  20. $setting['styleid'] = $site_multi_info['styleid'];
  21. $site_styles_table->searchWithTemplates();
  22. $site_styles_table->where('a.uniacid', $_W['uniacid']);
  23. if (!empty($_GPC['keyword'])) {
  24. $keyword = safe_gpc_string($_GPC['keyword']);
  25. $site_styles_table->where('a.name LIKE', "%$keyword%");
  26. }
  27. $styles = $site_styles_table->getall();
  28. $templates = uni_templates();
  29. $stylesResult = array();
  30. foreach ($templates as $k => $v) {
  31. if (!empty($keyword)) {
  32. if (strpos($v['title'], $keyword) !== false) {
  33. $stylesResult[$k] = array(
  34. 'templateid' => $v['id'],
  35. 'name' => $v['name'],
  36. 'title' => $v['title'],
  37. 'type' => $v['type']
  38. );
  39. }
  40. } else {
  41. $stylesResult[$k] = array(
  42. 'templateid' => $v['id'],
  43. 'name' => $v['name'],
  44. 'title' => $v['title'],
  45. 'type' => $v['type']
  46. );
  47. foreach ($styles as $style_val) {
  48. if ($v['id'] == $style_val['templateid']) {
  49. unset($stylesResult[$k]);
  50. }
  51. }
  52. }
  53. }
  54. $templates_id = array_keys($templates);
  55. foreach ($styles as $v) {
  56. if (!in_array($v['templateid'], $templates_id)) {
  57. continue;
  58. }
  59. $stylesResult[] = array(
  60. 'styleid' => $v['id'],
  61. 'templateid' => $v['templateid'],
  62. 'name' => $templates[$v['templateid']]['name'],
  63. 'title' => $v['name'],
  64. 'type' => $templates[$v['templateid']]['type']
  65. );
  66. }
  67. if (!empty($_GPC['type']) && $_GPC['type'] != 'all') {
  68. $tmp = array();
  69. foreach ($stylesResult as $k => $v) {
  70. if ($v['type'] == $_GPC['type']) {
  71. $tmp[] = $v;
  72. }
  73. }
  74. $stylesResult = $tmp;
  75. }
  76. array_multisort($stylesResult, SORT_DESC);
  77. $temtypes = ext_template_type();
  78. template('site/tpl-display');
  79. }
  80. if ($do == 'default') {
  81. $setting = uni_setting($_W['uniacid'], array('default_site'));
  82. $multi = $site_multi_table->getById($setting['default_site']);
  83. if (empty($multi)) {
  84. itoast('您的默认微站找不到,请联系网站管理员');
  85. }
  86. $styleid = intval($_GPC['styleid']);
  87. $style = $site_styles_table->getById($styleid);
  88. if (empty($style)) {
  89. itoast('抱歉,风格不存在或是您无权限使用!');
  90. }
  91. $templateid = $style['templateid'];
  92. $template = array();
  93. $templates = uni_templates();
  94. if (!empty($templates)) {
  95. foreach ($templates as $row) {
  96. if ($row['id'] == $templateid) {
  97. $template = $row;
  98. break;
  99. }
  100. }
  101. }
  102. if (empty($template)) {
  103. itoast('抱歉,模板不存在或是您无权限使用!');
  104. }
  105. $site_multi_table->fill(array('styleid' => $styleid))->where(array('uniacid' => $_W['uniacid'], 'id' => $setting['default_site']))->save();
  106. $styles = $site_styles_vars_table->getAllByStyleid($styleid);
  107. $styles_tmp = array_keys($styles);
  108. $templatedata = ext_template_manifest($template['name']);
  109. if (empty($styles)) {
  110. if (!empty($templatedata['settings'])) {
  111. foreach ($templatedata['settings'] as $list) {
  112. pdo_insert('site_styles_vars', array('variable' => $list['key'], 'content' => $list['value'], 'description' => $list['desc'], 'templateid' => $templateid, 'styleid' => $styleid, 'uniacid' => $_W['uniacid']));
  113. }
  114. }
  115. } else {
  116. if (!empty($templatedata['settings'])) {
  117. foreach ($templatedata['settings'] as $list) {
  118. if (!in_array($list['key'], $styles_tmp)) {
  119. pdo_insert('site_styles_vars', array(
  120. 'content' => $list['value'],
  121. 'templateid' => $templateid,
  122. 'styleid' => $styleid,
  123. 'variable' => $list['key'],
  124. 'description' => $list['desc'],
  125. 'uniacid' => $_W['uniacid']
  126. ));
  127. }
  128. }
  129. }
  130. }
  131. itoast('默认模板更新成功!', url('site/style/template'), 'success');
  132. }
  133. if ($do == 'designer') {
  134. $styleid = intval($_GPC['styleid']);
  135. $style = $site_styles_table->getById($styleid);
  136. if (empty($style)) {
  137. itoast('抱歉,风格不存在或是已经被删除!', '', 'error');
  138. }
  139. $templateid = $style['templateid'];
  140. $template = $site_templates_table->getById($templateid);
  141. if (empty($template)) {
  142. itoast('抱歉,模板不存在或是已经被删除!', '', 'error');
  143. }
  144. $styles = $site_styles_vars_table->getAllByStyleid($styleid);
  145. $systemtags = array(
  146. 'imgdir',
  147. 'indexbgcolor',
  148. 'indexbgimg',
  149. 'indexbgextra',
  150. 'fontfamily',
  151. 'fontsize',
  152. 'fontcolor',
  153. 'fontnavcolor',
  154. 'linkcolor',
  155. 'css'
  156. );
  157. if (checksubmit('submit')) {
  158. if (!empty($_GPC['style'])) {
  159. $_GPC['style'] = safe_gpc_array($_GPC['style']);
  160. foreach ($_GPC['style'] as $variable => $value) {
  161. if (!in_array($variable, $systemtags)) {
  162. continue;
  163. }
  164. $value = safe_gpc_html(htmlspecialchars_decode($value, ENT_QUOTES));
  165. if ($variable == 'imgdir') {
  166. $value = safe_gpc_path($value);
  167. }
  168. if (!empty($styles[$variable])) {
  169. if ($styles[$variable]['content'] != $value) {
  170. pdo_update('site_styles_vars', array('content' => $value), array(
  171. 'styleid' => $styleid,
  172. 'variable' => $variable,
  173. ));
  174. }
  175. unset($styles[$variable]);
  176. } elseif (!empty($value)) {
  177. pdo_insert('site_styles_vars', array(
  178. 'content' => $value,
  179. 'templateid' => $templateid,
  180. 'styleid' => $styleid,
  181. 'variable' => $variable,
  182. 'uniacid' => $_W['uniacid']
  183. ));
  184. }
  185. }
  186. }
  187. if (!empty($_GPC['custom']['name'])) {
  188. $_GPC['custom']['name'] = safe_gpc_array($_GPC['custom']['name']);
  189. foreach ($_GPC['custom']['name'] as $i => $variable) {
  190. if (preg_match('/[^0-9A-Za-z-_]/', $variable)) {
  191. continue;
  192. }
  193. $value = safe_gpc_string($_GPC['custom']['value'][$i]);
  194. $desc = safe_gpc_string($_GPC['custom']['desc'][$i]);
  195. if (!empty($value)) {
  196. if (!empty($styles[$variable])) {
  197. if ($styles[$variable] != $value) {
  198. pdo_update('site_styles_vars', array('content' => $value, 'description' => $desc), array(
  199. 'templateid' => $templateid,
  200. 'variable' => $variable,
  201. 'uniacid' => $_W['uniacid'],
  202. 'styleid' => $styleid
  203. ));
  204. }
  205. unset($styles[$variable]);
  206. } else {
  207. pdo_insert('site_styles_vars', array(
  208. 'content' => $value,
  209. 'templateid' => $templateid,
  210. 'styleid' => $styleid,
  211. 'variable' => $variable,
  212. 'description' => $desc,
  213. 'uniacid' => $_W['uniacid']
  214. ));
  215. }
  216. }
  217. }
  218. }
  219. if (!empty($styles)) {
  220. $stylekeys = array_keys($styles);
  221. foreach ($stylekeys as $value) {
  222. pdo_delete('site_styles_vars', array('uniacid' => $_W['uniacid'], 'styleid' => $styleid, 'variable' => $value));
  223. }
  224. }
  225. $site_styles_table->fill(array('name' => safe_gpc_string($_GPC['name'])))->where(array('id' => $styleid, 'uniacid' => $_W['uniacid']))->save();
  226. itoast('更新风格成功!', url('site/style'), 'success');
  227. }
  228. template('site/tpl-post');
  229. }
  230. if ($do == 'module') {
  231. if (empty($_W['isfounder'])) {
  232. itoast('您无权进行该操作!', '', '');
  233. }
  234. $setting = uni_setting($_W['uniacid'], array('default_site'));
  235. $multi_info = $site_multi_table->getById($setting['default_site']);
  236. $styleid = !empty($multi_info) ? $multi_info['styleid'] : 0;
  237. $style_info = $site_styles_table->getById($styleid);
  238. $templateid = !empty($style_info) ? $style_info['templateid'] : 0;
  239. $ts = uni_templates();
  240. $currentTemplate = !empty($ts[$templateid]) ? $ts[$templateid]['name'] : 'default';
  241. $modules = uni_modules();
  242. $path = IA_ROOT . '/addons';
  243. if (is_dir($path)) {
  244. if ($handle = opendir($path)) {
  245. while (false !== ($modulepath = readdir($handle))) {
  246. if ($modulepath != '.' && $modulepath != '..' && !empty($modules[$modulepath])) {
  247. if (is_dir($path . '/' . $modulepath . '/template/mobile')) {
  248. if ($handle1 = opendir($path . '/' . $modulepath . '/template/mobile')) {
  249. while (false !== ($mobilepath = readdir($handle1))) {
  250. if ($mobilepath != '.' && $mobilepath != '..' && strexists($mobilepath, '.html')) {
  251. $templates[$modulepath][] = $mobilepath;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. }
  260. template('site/style');
  261. }
  262. if ($do == 'build') {
  263. $templateid = intval($_GPC['styleid']);
  264. $template = array();
  265. $templates = uni_templates();
  266. if (!empty($templates)) {
  267. foreach ($templates as $row) {
  268. if ($row['id'] == $templateid) {
  269. $template = $row;
  270. break;
  271. }
  272. }
  273. }
  274. if (empty($template)) {
  275. itoast('抱歉,模板不存在或是您无权限使用!', '', 'error');
  276. }
  277. list($templatetitle) = explode('_', $template['title']);
  278. $newstyle = array(
  279. 'uniacid' => $_W['uniacid'],
  280. 'name' => $templatetitle.'_'.random(4),
  281. 'templateid' => $template['id'],
  282. );
  283. pdo_insert('site_styles', $newstyle);
  284. $id = pdo_insertid();
  285. $templatedata = ext_template_manifest($template['name']);
  286. if (!empty($templatedata['settings'])) {
  287. foreach ($templatedata['settings'] as $style_var) {
  288. if (!empty($style_var['key']) && !empty($style_var['desc'])) {
  289. pdo_insert('site_styles_vars', array(
  290. 'content' => $style_var['value'],
  291. 'templateid' => $templateid,
  292. 'styleid' => $id,
  293. 'variable' => $style_var['key'],
  294. 'uniacid' => $_W['uniacid'],
  295. 'description' => $style_var['desc'],
  296. ));
  297. }
  298. }
  299. }
  300. itoast('风格创建成功,进入“设计风格”界面。', url('site/style/designer', array('templateid' => $template['id'], 'styleid' => $id)), 'success');
  301. }
  302. if ($do == 'copy') {
  303. $styleid = intval($_GPC['styleid']);
  304. $style = $site_styles_table->getById($styleid);
  305. if (empty($style)) {
  306. itoast('抱歉,风格不存在或是已经被删除!', '', 'error');
  307. }
  308. $templateid = $style['templateid'];
  309. $template = $site_templates_table->getById($templateid);
  310. if (empty($template)) {
  311. itoast('抱歉,模板不存在或是已经被删除!', '', 'error');
  312. }
  313. list($name) = explode('_', $style['name']);
  314. $newstyle = array(
  315. 'uniacid' => $_W['uniacid'],
  316. 'name' => $name.'_'.random(4),
  317. 'templateid' => $style['templateid'],
  318. );
  319. pdo_insert('site_styles', $newstyle);
  320. $id = pdo_insertid();
  321. $styles = $site_styles_vars_table->getAllByStyleid($styleid);
  322. if (!empty($styles)) {
  323. foreach($styles as $data) {
  324. $data['styleid'] = $id;
  325. pdo_insert('site_styles_vars', $data);
  326. }
  327. }
  328. itoast('风格复制成功,进入“设计风格”界面。', url('site/style/designer', array('templateid' => $style['templateid'], 'styleid' => $id)), 'success');
  329. }
  330. if ($do == 'del') {
  331. $styleid = intval($_GPC['styleid']);
  332. pdo_delete('site_styles_vars', array('uniacid' => $_W['uniacid'], 'styleid' => $styleid));
  333. pdo_delete('site_styles', array('uniacid' => $_W['uniacid'], 'id' => $styleid));
  334. itoast('删除风格成功。', referer(), 'success');
  335. }