/** * @brief 获取到商家中心的导航菜单和左边栏菜单 * * @return array $res */ private function __getMenu() { $currentPermission = shopAuth::getSellerPermission(); $defaultActionName = route::current()->getActionName(); $shopMenu = config::get('shop'); $shortcutMenuAction = $this->getShortcutMenu(); $sidebar['commonUser']['label'] = '常用菜单'; $sidebar['commonUser']['shortcutMenu'] = true; $sidebar['commonUser']['active'] = true; //是否展开 $sidebar['commonUser']['icon'] = 'glyphicon glyphicon-heart'; //$sidebar['commonUser']['menu'] = $commonUserMenu; foreach ((array) $shopMenu as $menu => $row) { if ($row['display'] === false) { continue; } foreach ((array) $row['menu'] as $k => $params) { //编辑常用菜单使用 if ($params['display'] !== false && (!$currentPermission || in_array($params['as'], $currentPermission))) { $allMenu[$menu]['label'] = $row['label']; if (in_array($params['action'], $shortcutMenuAction)) { $sidebar['commonUser']['menu'][] = $params; $params['isShortcutMenu'] = true; } $allMenu[$menu]['menu'][] = $params; } if ($row['shopIndex'] || !$currentPermission || $params['display'] && in_array($params['as'], $currentPermission)) { if (!$navbar[$menu]) { $navbar[$menu]['label'] = $row['label']; $navbar[$menu]['icon'] = $row['icon']; $navbar[$menu]['action'] = $navbar[$menu]['action'] ? $navbar[$menu]['action'] : $params['action']; $navbar[$menu]['default'] = false; } } //如果为当前的路由则高亮 if (!$navbar[$menu]['default'] && $params['action'] == $defaultActionName && $navbar[$menu]) { $navbar[$menu]['default'] = true; $selectMenu = $menu; } } if (!$row['shopIndex'] && $selectMenu == $menu) { foreach ((array) $row['menu'] as $k => $params) { $sidebar[$menu]['active'] = true; $sidebar[$menu]['label'] = $row['label']; $sidebar[$menu]['icon'] = $row['icon']; if (!$currentPermission || in_array($params['as'], $currentPermission)) { $params['default'] = $params['action'] == $defaultActionName ? true : false; $sidebar[$menu]['menu'][] = $params; } } } } $res['all'] = $allMenu; $res['navbar'] = $navbar; $res['sidebar'] = $sidebar; return $res; }
public static function get($url) { $url = preg_replace('/^(\\/)/', '', $url); $new_url = $url; // REST API if (preg_match('/\\.([\\-_a-zA-Z]+)$/', $new_url)) { $split = explode('.', $new_url); api::set(array_pop($split)); $new_url = implode('.', $split); } // Static routes if (!empty(self::$route[$url])) { $new_url = self::$route[$url]; } // Regex routes $route_keys = array_keys(self::$route); foreach ($route_keys as $okey) { $key = '/^' . str_replace('/', '\\/', $okey) . '$/'; if (preg_match($key, $url)) { if (!is_array(self::$route[$okey])) { $new_url = preg_replace($key, self::$route[$okey], $url); } else { /* Run regex replace on keys */ $new_url = self::$route[$okey]; // Controller if (isset($new_url['controller'])) { $new_url['controller'] = preg_replace($key, $new_url['controller'], $url); } // Function if (isset($new_url['function'])) { $new_url['function'] = preg_replace($key, $new_url['function'], $url); } // Arguments if (isset($new_url['arguments'])) { $x = 0; while (isset($new_url['arguments'][$x])) { $new_url['arguments'][$x] = preg_replace($key, $new_url['arguments'][$x], $url); $x += 1; } } } } } // If URL is empty use default route if (empty($new_url) or $new_url == '/') { $new_url = self::$route['default_route']; } // Turn into array if (!is_array($new_url)) { // Remove the /index.php/ at the beginning //$new_url = preg_replace('/^(\/)/','',$url); $tmp_url = explode('/', $new_url); $new_url = array('controller' => $tmp_url[0], 'function' => 'index', 'arguments' => array(), 'string' => $new_url, 'segments' => $tmp_url); // Function if (!empty($tmp_url[1])) { $new_url['function'] = $tmp_url[1]; } // Arguments $x = 2; while (isset($tmp_url[$x])) { $new_url['arguments'][] = $tmp_url[$x]; $x += 1; } } else { // Add missing keys if (!isset($new_url['function'])) { $new_url['function'] = 'index'; } if (!isset($new_url['arguments'])) { $new_url['arguments'] = array(); } // Build string key for URL array // Controller $s = $new_url['controller']; // Function if (isset($new_url['function'])) { $s .= "/{$new_url['function']}"; } // Arguments foreach ($new_url['arguments'] as $arg) { $s .= "/{$arg}"; } $new_url['string'] = $s; // Add segments key $new_url['segments'] = explode('/', $new_url['string']); } // Controller class $new_url['controller_class'] = explode('/', $new_url['controller']); $new_url['controller_class'] = end($new_url['controller_class']); self::$current = $new_url; return $new_url; }