人人商城

style.ctrl.php 12KB

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