multi.ctrl.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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('site');
  8. load()->model('extension');
  9. $dos = array('display', 'post', 'del', 'default', 'copy', 'switch', 'quickmenu_display', 'quickmenu_post');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. permission_check_account_user('platform_site_multi');
  12. $setting = uni_setting($_W['uniacid'], 'default_site');
  13. $default_site = intval($setting['default_site']);
  14. $default_site_status = pdo_getcolumn('site_multi', array('id' => $default_site), 'status');
  15. if ($default_site_status != 1) {
  16. pdo_update('site_multi', array('status' => 1), array('id' => $default_site));
  17. }
  18. if ($do == 'post') {
  19. if ($_W['isajax'] && $_W['ispost']) {
  20. $name = safe_gpc_string($_GPC['name']);
  21. $sql = "SELECT s.*, t.`name` AS `tname`, t.`title`, t.`type` FROM " . tablename('site_styles') . " AS s LEFT JOIN " . tablename('site_templates') . " AS t ON s.`templateid` = t.`id` WHERE s.`uniacid` = :uniacid AND s.`name` LIKE :name";
  22. $styles = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'], ':name' => "%{$name}%"));
  23. iajax(0, $styles, '');
  24. }
  25. $id = intval($_GPC['multiid']);
  26. if (checksubmit('submit')) {
  27. $bindhost = parse_url($_W['siteroot']);
  28. if ($bindhost['host'] == safe_gpc_string($_GPC['bindhost'])) {
  29. itoast('绑定域名有误', referer(), 'error');
  30. }
  31. $data = array(
  32. 'uniacid' => $_W['uniacid'],
  33. 'title' => safe_gpc_string($_GPC['title']),
  34. 'styleid' => intval($_GPC['styleid']),
  35. 'status' => intval($_GPC['status']),
  36. 'site_info' => iserializer(array(
  37. 'thumb' => safe_gpc_string($_GPC['thumb']),
  38. 'keyword' => !empty($_GPC['keyword']) ? safe_gpc_string($_GPC['keyword']) : '微官网',
  39. 'description' => safe_gpc_string($_GPC['description']),
  40. 'footer' => htmlspecialchars($_GPC['footer'])
  41. )),
  42. 'bindhost' => safe_gpc_string($_GPC['bindhost']),
  43. );
  44. if (!empty($id)) {
  45. if ($id == $default_site) {
  46. $data['status'] = 1;
  47. }
  48. pdo_update('site_multi', $data, array('id' => $id));
  49. } else {
  50. pdo_insert('site_multi', $data);
  51. $id = pdo_insertid();
  52. }
  53. $cover = array(
  54. 'uniacid' => $_W['uniacid'],
  55. 'title' => $data['title'],
  56. 'keyword' => !empty($_GPC['keyword']) ? safe_gpc_string($_GPC['keyword']) : '微官网',
  57. 'url' => url('home', array('i' => $_W['uniacid'], 't' => $id)),
  58. 'description' => safe_gpc_string($_GPC['description']),
  59. 'thumb' => safe_gpc_string($_GPC['thumb']),
  60. 'module' => 'site',
  61. 'multiid' => $id,
  62. );
  63. site_cover($cover);
  64. itoast('更新站点信息成功!', url('site/multi/display'), 'success');
  65. }
  66. if (!empty($id)) {
  67. $multi = pdo_fetch('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  68. if (empty($multi)) {
  69. itoast('微站不存在或已删除', referer(), 'error');
  70. }
  71. $multi['site_info'] = iunserializer($multi['site_info']) ? iunserializer($multi['site_info']) : array();
  72. }
  73. $temtypes = ext_template_type();
  74. $temtypes[] = array('name' => 'all', 'title' => '全部');
  75. $sql = 'SELECT `s`.*, `t`.`id` as `tid`, `t`.`name` AS `tname`, `t`.`title`, `t`.`type`, `t`.`sections` FROM ' . tablename('site_styles') . ' AS `s` LEFT JOIN ' . tablename('site_templates') . ' AS `t` ON `s`.`templateid` = `t`.`id` WHERE `s`.`uniacid` = :uniacid';
  76. $styles = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']), 'id');
  77. if (empty($multi)) {
  78. $multi = array(
  79. 'site_info' => array(),
  80. 'status' => 1,
  81. );
  82. }
  83. $multi['style'] = $styles[$multi['styleid']];
  84. template('site/post');
  85. }
  86. if ($do == 'display') {
  87. $pindex = max(1, intval($_GPC['page']));
  88. $psize = 10;
  89. $condition = '';
  90. $params = array();
  91. if (!empty($_GPC['keyword'])) {
  92. $condition .= " AND `title` LIKE :keyword";
  93. $params[':keyword'] = "%{$_GPC['keyword']}%";
  94. }
  95. $templates = uni_templates();
  96. $params[':uniacid'] = $_W['uniacid'];
  97. $multis = pdo_fetchall('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid'.$condition.' ORDER BY id ASC LIMIT '.($pindex -1)* $psize.','.$psize, $params);
  98. foreach ($multis as &$li) {
  99. $li['style'] = pdo_fetch('SELECT * FROM ' .tablename('site_styles') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $li['styleid']));
  100. $li['template'] = pdo_fetch("SELECT * FROM ".tablename('site_templates')." WHERE id = :id", array(':id' => $li['style']['templateid']));
  101. $li['site_info'] = (array)iunserializer($li['site_info']);
  102. $li['site_info']['thumb'] = tomedia($li['site_info']['thumb']);
  103. if (file_exists('../app/themes/'.$li['template']['name'].'/preview.jpg')) {
  104. $li['preview_thumb'] = $_W['siteroot'].'app/themes/'.$li['template']['name'].'/preview.jpg';
  105. } else {
  106. $li['preview_thumb'] = $_W['siteroot'].'web/resource/images/nopic-203.png';
  107. }
  108. }
  109. unset($li);
  110. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('site_multi') . " WHERE uniacid = :uniacid".$condition, $params);
  111. $pager = pagination($total, $pindex, $psize);
  112. template('site/display');
  113. }
  114. if ($do == 'del') {
  115. $id = intval($_GPC['id']);
  116. if ($default_site == $id) {
  117. itoast('您删除的微站是默认微站,删除前先指定其他微站为默认微站', referer(), 'error');
  118. }
  119. pdo_delete('site_nav', array('uniacid' => $_W['uniacid'], 'multiid' => $id));
  120. $rid = pdo_fetchcolumn('SELECT rid FROM ' .tablename('cover_reply') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  121. uni_delete_rule($rid, 'cover_reply');
  122. pdo_delete('site_multi', array('uniacid' => $_W['uniacid'], 'id' => $id));
  123. itoast('删除微站成功', referer(), 'success');
  124. }
  125. if ($do == 'copy') {
  126. $id = intval($_GPC['multiid']);
  127. $multi = pdo_fetch('SELECT * FROM ' . tablename('site_multi') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  128. if (empty($multi)) {
  129. itoast('微站不存在或已删除', referer(), 'error');
  130. }
  131. $multi['title'] = $multi['title'] . '_' . random(6);
  132. unset($multi['id']);
  133. pdo_insert('site_multi', $multi);
  134. $multi_id = pdo_insertid();
  135. if (!$multi_id) {
  136. itoast('复制微站出错', '', 'error');
  137. } else {
  138. $navs = pdo_fetchall('SELECT * FROM ' . tablename('site_nav') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  139. if (!empty($navs)) {
  140. foreach ($navs as &$nav) {
  141. unset($nav['id']);
  142. $nav['multiid'] = $multi_id;
  143. pdo_insert('site_nav', $nav);
  144. }
  145. unset($nav);
  146. }
  147. $cover = pdo_fetch('SELECT * FROM ' . tablename('cover_reply') . ' WHERE uniacid = :uniacid AND multiid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $id));
  148. if (!empty($cover)) {
  149. $rule = pdo_fetch('SELECT * FROM ' . tablename('rule') . ' WHERE uniacid = :uniacid AND id = :id', array(':uniacid' => $_W['uniacid'], ':id' => $cover['rid']));
  150. $keywords = pdo_fetchall('SELECT * FROM ' . tablename('rule_keyword') . ' WHERE uniacid = :uniacid AND rid = :id', array(':uniacid' => $_W['uniacid'], ':id' => $cover['rid']));
  151. if (!empty($rule) && !empty($keywords)) {
  152. $rule['name'] = $multi['title'] . '入口设置';
  153. unset($rule['id']);
  154. pdo_insert('rule', $rule);
  155. $new_rid = pdo_insertid();
  156. foreach($keywords as &$keyword) {
  157. unset($keyword['id']);
  158. $keyword['rid'] = $new_rid;
  159. pdo_insert('rule_keyword', $keyword);
  160. }
  161. unset($keyword);
  162. unset($cover['id']);
  163. $cover['title'] = $multi['title'] . '入口设置';
  164. $cover['multiid'] = $multi_id;
  165. $cover['rid'] = $new_rid;
  166. pdo_insert('cover_reply', $cover);
  167. }
  168. }
  169. itoast('复制微站成功', url('site/multi/post', array('multiid' => $multi_id)), 'success');
  170. }
  171. }
  172. if ($do == 'switch') {
  173. $id = intval($_GPC['id']);
  174. $multi_info = pdo_get('site_multi', array('id' => $id, 'uniacid' => $_W['uniacid']));
  175. if(empty($multi_info)) {
  176. itoast('微站不存在或已删除', referer(), 'error');
  177. }
  178. $data = array('status' => $multi_info['status'] == 1 ? 0 : 1);
  179. $result = pdo_update('site_multi', $data, array('id' => $id, 'uniacid' => $_W['uniacid']));
  180. if(!empty($result)) {
  181. iajax(0, '更新成功!', '');
  182. }else {
  183. iajax(-1, '请求失败!', '');
  184. }
  185. }
  186. if ($do == 'quickmenu_display' && $_W['isajax'] && $_W['ispost'] && $_W['role'] != 'operator') {
  187. $multiid = intval($_GPC['multiid']);
  188. if($multiid > 0){
  189. $page = pdo_get('site_page', array('multiid' => $multiid, 'type' => 2));
  190. }
  191. $params = !empty($page['params']) ? $page['params'] : 'null';
  192. $status = $page['status'] == 1 ? 1 : 0;
  193. $modules = uni_modules();
  194. $modules = !empty($modules) ? $modules : 'null';
  195. iajax(0, array('params' => json_decode($params), 'status' => $status, 'modules' => $modules), '');
  196. }
  197. if ($do == 'quickmenu_post' && $_W['isajax'] && $_W['ispost']) {
  198. $params = $_GPC['postdata']['params'];
  199. if (empty($params)) {
  200. iajax(1, '请您先设计手机端页面.');
  201. }
  202. foreach ($params['position'] as &$val) {
  203. $val = $val == 'true' ? 1 : 0;
  204. }
  205. unset($val);
  206. $html = safe_gpc_html(htmlspecialchars_decode($_GPC['postdata']['html'], ENT_QUOTES));
  207. $html = preg_replace('/background\-image\:(\s)*url\(\"(.*)\"\)/U', 'background-image: url($2)', $html);
  208. $data = array(
  209. 'uniacid' => $_W['uniacid'],
  210. 'multiid' => intval($_GPC['multiid']),
  211. 'title' => '快捷菜单',
  212. 'description' => '',
  213. 'status' => intval($_GPC['status']),
  214. 'type' => 2,
  215. 'params' => json_encode($params),
  216. 'html' => $html,
  217. 'createtime' => TIMESTAMP,
  218. );
  219. $id = pdo_fetchcolumn("SELECT id FROM ".tablename('site_page')." WHERE multiid = :multiid AND type = 2", array(':multiid' => intval($_GPC['multiid'])));
  220. if (!empty($id)) {
  221. $result = pdo_update('site_page', $data, array('id' => $id, 'uniacid' => $_W['uniacid']));
  222. } else {
  223. $result = pdo_insert('site_page', $data);
  224. $id = pdo_insertid();
  225. }
  226. if ($result) {
  227. iajax(0, '保存成功!', '');
  228. } else {
  229. iajax(1, '保存失败!', '');
  230. }
  231. }