nav.ctrl.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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('module');
  8. $dos = array('home', 'profile', 'homemenu_display', 'homemenu_post', 'homemenu_del', 'homemenu_switch');
  9. $do = in_array($do, $dos) ? $do : 'home';
  10. $system_modules = module_system();
  11. if (!in_array($_GPC['m'], $system_modules)) {
  12. permission_check_account_user('', true, 'nav');
  13. }
  14. $modulename = $_GPC['m'];
  15. if ($do == 'homemenu_display') {
  16. $multiid = intval($_GPC['multiid']);
  17. $navs = pdo_getall('site_nav', array('uniacid' => $_W['uniacid'], 'position' => '1', 'multiid' => $multiid), array(), '', array('displayorder DESC', 'id ASC'));
  18. $navigations = array();
  19. if (!empty($navs)) {
  20. foreach ($navs as $nav) {
  21. if (is_serialized($nav['css'])) {
  22. $nav['css'] = iunserializer($nav['css']);
  23. if (empty($nav['css']['icon']['icon'])) {
  24. $nav['css']['icon']['icon'] = 'fa fa-external-link';
  25. }
  26. }
  27. $navigations[] = array(
  28. 'id' => $nav['id'],
  29. 'module' => $nav['module'],
  30. 'name' => $nav['name'],
  31. 'url' => $nav['url'],
  32. 'from' => $nav['module'] ? 'define' : 'custom',
  33. 'status' => $nav['status'],
  34. 'remove' => true,
  35. 'displayorder' => $nav['displayorder'],
  36. 'icon' => $nav['icon'],
  37. 'css' => $nav['css'],
  38. 'section' => $nav['section'],
  39. 'description' => $nav['description']
  40. );
  41. }
  42. }
  43. iajax(0, $navigations, '');
  44. }
  45. if ($do == 'homemenu_post') {
  46. $multiid = intval($_GPC['multiid']);
  47. $post = $_GPC['menu_info'];
  48. if (empty($post['name'])) {
  49. iajax(-1, '抱歉,请输入导航菜单的名称!', '');
  50. }
  51. if (strexists($post['url'], 'tel')) {
  52. $url = safe_gpc_string($post['url'], false);
  53. } else {
  54. $url = safe_gpc_url($post['url'], false);
  55. }
  56. if (is_array($post['section']) && !empty($post['section'])) {
  57. if (intval($post['section']['num']) > 10) {
  58. $section_num = 10;
  59. } else {
  60. $section_num = intval($post['section']['num']);
  61. }
  62. } else {
  63. $section_num = 0;
  64. }
  65. $data = array(
  66. 'uniacid' => $_W['uniacid'],
  67. 'multiid' => $multiid,
  68. 'section' => $section_num,
  69. 'name' => safe_gpc_string($post['name']),
  70. 'description' => safe_gpc_string($post['description']),
  71. 'displayorder' => intval($post['displayorder']),
  72. 'url' => $url,
  73. 'status' => intval($post['status']),
  74. 'position' => 1
  75. );
  76. $icontype = safe_gpc_string($post['icontype']);
  77. if ($icontype == 1) {
  78. $data['icon'] = '';
  79. $data['css'] = serialize(array(
  80. 'icon' => array(
  81. 'font-size' => intval($post['css']['icon']['width']),
  82. 'color' => safe_gpc_string($post['css']['icon']['color']),
  83. 'width' => intval($post['css']['icon']['width']),
  84. 'icon' => empty($post['css']['icon']['icon']) ? 'fa fa-external-link' : safe_gpc_string($post['css']['icon']['icon']),
  85. ),
  86. 'name' => array(
  87. 'color' => safe_gpc_string($post['css']['icon']['color']),
  88. ),
  89. )
  90. );
  91. } else {
  92. $data['css'] = '';
  93. $data['icon'] = $post['icon'];
  94. }
  95. if (empty($post['id'])) {
  96. pdo_insert('site_nav', $data);
  97. } else {
  98. pdo_update('site_nav', $data, array('id' => $post['id'], 'uniacid' => $_W['uniacid']));
  99. }
  100. iajax(0, '更新成功!', '');
  101. }
  102. if ($do == 'homemenu_del') {
  103. $id = intval($_GPC['id']);
  104. $nav_exist = pdo_get('site_nav', array('id' => $id, 'uniacid' => $_W['uniacid']));
  105. if (empty($nav_exist)) {
  106. iajax(-1, '本公众号不存在该导航!', '');
  107. } else {
  108. $nav_del = pdo_delete('site_nav', array('id' => $id));
  109. if (!empty($nav_del)) {
  110. iajax(0, '删除成功!', '');
  111. } else {
  112. iajax(1, '删除失败!', '');
  113. }
  114. }
  115. exit;
  116. }
  117. if ($do == 'homemenu_switch') {
  118. $id = intval($_GPC['id']);
  119. $nav_exist = pdo_get('site_nav', array('id' => $id, 'uniacid' => $_W['uniacid']));
  120. if (empty($nav_exist)) {
  121. iajax(-1, '本公众号不存在该导航');
  122. } else {
  123. $status = $nav_exist['status'] == 1 ? 0 : 1;
  124. $nav_update = pdo_update('site_nav', array('status' => $status), array('id' => $id, 'uniacid' => $_W['uniacid']));
  125. if (!empty($nav_update)) {
  126. iajax(0, '更新成功!', '');
  127. } else {
  128. iajax(1, '更新失败!', '');
  129. }
  130. }
  131. }
  132. if ($do == 'home' || $do == 'profile') {
  133. $modules = uni_modules();
  134. $bindings = array();
  135. define('IN_MODULE', $modulename);
  136. if (!empty($modulename)) {
  137. $modulenames = array($modulename);
  138. } else {
  139. $modulenames = array_keys($modules);
  140. }
  141. $_W['current_module'] = module_fetch($modulename);
  142. foreach ($modulenames as $modulename) {
  143. $entries = module_entries($modulename, array($do));
  144. if (!empty($entries[$do])) {
  145. $bindings[$modulename] = $entries[$do];
  146. }
  147. }
  148. $entries = array();
  149. if (!empty($bindings)) {
  150. foreach ($bindings as $modulename => $group) {
  151. foreach ($group as $bind) {
  152. $entries[] = array('module' => $modulename, 'from' => $bind['from'], 'title' => $bind['title'], 'url' => $bind['url'], 'icon' => $bind['icon']);
  153. }
  154. }
  155. }
  156. template('site/nav');
  157. }