nav.ctrl.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 = system_modules();
  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. }
  24. if (empty($nav['css']['icon']['icon'])) {
  25. $nav['css']['icon']['icon'] = 'fa fa-external-link';
  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. $url = ((strexists($post['url'], 'http://') || strexists($post['url'], 'https://')) && !strexists($post['url'], '#wechat_redirect')) ? $post['url'] . '#wechat_redirect' : $post['url'];
  52. if (is_array($post['section']) && !empty($post['section'])) {
  53. if (intval($post['section']['num']) > 10) {
  54. $section_num = 10;
  55. } else {
  56. $section_num = intval($post['section']['num']);
  57. }
  58. } else {
  59. $section_num = 0;
  60. }
  61. $data = array(
  62. 'uniacid' => $_W['uniacid'],
  63. 'multiid' => $multiid,
  64. 'section' => $section_num,
  65. 'name' => trim($post['name']),
  66. 'description' => trim($post['description']),
  67. 'displayorder' => intval($post['displayorder']),
  68. 'url' => $url,
  69. 'status' => intval($post['status']),
  70. 'position' => 1
  71. );
  72. $icontype = $post['icontype'];
  73. if ($icontype == 1) {
  74. $data['icon'] = '';
  75. $data['css'] = serialize(array(
  76. 'icon' => array(
  77. 'font-size' => $post['css']['icon']['width'],
  78. 'color' => $post['css']['icon']['color'],
  79. 'width' => $post['css']['icon']['width'],
  80. 'icon' => empty($post['css']['icon']['icon']) ? 'fa fa-external-link' : $post['css']['icon']['icon'],
  81. ),
  82. 'name' => array(
  83. 'color' => $post['css']['icon']['color'],
  84. ),
  85. )
  86. );
  87. } else {
  88. $data['css'] = '';
  89. $data['icon'] = $post['icon'];
  90. }
  91. if (empty($post['id'])) {
  92. pdo_insert('site_nav', $data);
  93. } else {
  94. pdo_update('site_nav', $data, array('id' => $post['id']));
  95. }
  96. iajax(0, '更新成功!', '');
  97. }
  98. if ($do == 'homemenu_del') {
  99. $id = intval($_GPC['id']);
  100. $nav_exist = pdo_get('site_nav', array('id' => $id, 'uniacid' => $_W['uniacid']));
  101. if (empty($nav_exist)) {
  102. iajax(-1, '本公众号不存在该导航!', '');
  103. } else {
  104. $nav_del = pdo_delete('site_nav', array('id' => $id));
  105. if (!empty($nav_del)) {
  106. iajax(0, '删除成功!', '');
  107. } else {
  108. iajax(1, '删除失败!', '');
  109. }
  110. }
  111. exit;
  112. }
  113. if ($do == 'homemenu_switch') {
  114. $id = intval($_GPC['id']);
  115. $nav_exist = pdo_get('site_nav', array('id' => $id, 'uniacid' => $_W['uniacid']));
  116. if (empty($nav_exist)) {
  117. iajax(-1, '本公众号不存在该导航');
  118. } else {
  119. $status = $nav_exist['status'] == 1 ? 0 : 1;
  120. $nav_update = pdo_update('site_nav', array('status' => $status), array('id' => $id));
  121. if (!empty($nav_update)) {
  122. iajax(0, '更新成功!', '');
  123. } else {
  124. iajax(1, '更新失败!', '');
  125. }
  126. }
  127. }
  128. if ($do == 'home' || $do == 'profile') {
  129. $modules = uni_modules();
  130. $bindings = array();
  131. define('IN_MODULE', $modulename);
  132. if (!empty($modulename)) {
  133. $modulenames = array($modulename);
  134. } else {
  135. $modulenames = array_keys($modules);
  136. }
  137. $_W['current_module'] = module_fetch($modulename);
  138. foreach ($modulenames as $modulename) {
  139. $entries = module_entries($modulename, array($do));
  140. if (!empty($entries[$do])) {
  141. $bindings[$modulename] = $entries[$do];
  142. }
  143. }
  144. $entries = array();
  145. if (!empty($bindings)) {
  146. foreach ($bindings as $modulename => $group) {
  147. foreach ($group as $bind) {
  148. $entries[] = array('module' => $modulename, 'from' => $bind['from'], 'title' => $bind['title'], 'url' => $bind['url'], 'icon' => $bind['icon']);
  149. }
  150. }
  151. }
  152. template('site/nav');
  153. }