public function getRouting($route = array(), $dispatch = true) { if ($this->_routes === null || $dispatch) { $routes = parent::getRouting($route); /** * Extend routing via plugin routes * @event routing * @param array $routes * @return array routes collected for every plugin */ $result = wa()->event(array('site', 'routing'), $routes); $all_plugins_routes = array(); foreach ($result as $plugin_id => $routing_rules) { if ($routing_rules) { $plugin = str_replace('-plugin', '', $plugin_id); foreach ($routing_rules as $url => &$route) { if (!is_array($route)) { list($route_ar['module'], $route_ar['action']) = explode('/', $route); $route = $route_ar; } $route['plugin'] = $plugin; $all_plugins_routes[$url] = $route; } unset($route); } } $routes = array_merge($all_plugins_routes, $routes); if ($dispatch) { return $routes; } $this->_routes = $routes; } return $this->_routes; }
public function getRouting($route = array(), $dispatch = false) { $url_type = isset($route['url_type']) ? $route['url_type'] : 0; if (!isset($this->_routes[$url_type]) || $dispatch) { $routes = parent::getRouting($route); if ($routes) { if (isset($routes[$url_type])) { $routes = $routes[$url_type]; } else { $routes = $routes[0]; } } // for URL <category_url>/<product_url>/ if ($dispatch && $url_type == 2) { $category_model = new shopCategoryModel(); $categories = $category_model->getByRoute(wa()->getRouting()->getDomain(null, true) . '/' . $route['url']); $categories_routes = array(); foreach ($categories as $c) { $categories_routes[$c['full_url'] . '/'] = array('module' => 'frontend', 'action' => 'category', 'category_id' => $c['id']); } $routes = array_merge($categories_routes, $routes); } /** * Extend routing via plugin routes * @event routing * @param array $routes * @return array $routes routes collected for every plugin */ $result = wa()->event(array($this->application, 'routing'), $route); $all_plugins_routes = array(); foreach ($result as $plugin_id => $routing_rules) { if ($routing_rules) { $plugin = str_replace('-plugin', '', $plugin_id); /* if ($url_type == 0) { $routing_rules = $routing_rules[0]; } else { $routing_rules = $routing_rules[1]; } */ foreach ($routing_rules as $url => &$route) { if (!is_array($route)) { list($route_ar['module'], $route_ar['action']) = explode('/', $route); $route = $route_ar; } $route['plugin'] = $plugin; $all_plugins_routes[$url] = $route; } unset($route); } } $routes = array_merge($all_plugins_routes, $routes); if ($dispatch) { return $routes; } $this->_routes[$url_type] = $routes; } return $this->_routes[$url_type]; }
public function getRouting($route = array(), $dispatch = false) { static $routes_cache = array(); $key = md5(serialize($route)); if (!isset($routes_cache[$key])) { $routes = parent::getRouting(); if ($routes) { $blog_id = isset($route['blog_url_type']) ? $route['blog_url_type'] : 0; switch (intval($blog_id)) { case -1: $rules = $routes[2]; break; case 0: $rules = $routes[0]; break; default: $rules = $routes[1]; break; } $post_url = isset($route['post_url_type']) ? $route['post_url_type'] : 0; $pattern = false; $year = '((19|20)[\\d]{2})'; $month = '([0]?\\d|1[0-2])'; $day = '([0-2]\\d|3[0-1]|\\d)'; switch ($post_url) { case 3: $pattern = '<post_year:' . $year . '>/<post_month:' . $month . '>/<post_day:' . $day . '>/<post_url>'; break; case 2: $pattern = '<post_year:' . $year . '>/<post_month:' . $month . '>/<post_url>'; break; case 1: $pattern = '<post_year:' . $year . '>/<post_url>'; break; case 0: default: break; } /** * Extend routing via plugin routes * @event routing * @param array $route * @return array route */ $result = wa()->event(array('blog', 'routing'), $route); $plugin_routes = array(); foreach ($result as $rs) { $plugin_routes = array_merge($plugin_routes, $rs); } if ($plugin_routes) { $rules = array_merge($plugin_routes, $rules); } if ($pattern) { $new_rules = array(); foreach ($rules as $rule_id => $rule) { if (strpos($rule_id, '<post_url>') === false) { $new_rules[$rule_id] = $rule; } else { $rule_id = str_replace('<post_url>', $pattern, $rule_id); $new_rules[$rule_id] = $rule; } } $rules = $new_rules; } $routes_cache[$key] = $rules; } else { $routes_cache[$key] = array(); } } return $routes_cache[$key]; }
public function getRouting($route = array()) { $url_type = isset($route['url_type']) ? $route['url_type'] : 0; $routes = parent::getRouting($route); if ($routes) { if ($url_type == 0) { $routes = $routes[0]; } else { $routes = $routes[1]; } } /** * Extend routing via plugin routes * @event routing * @param array $routes * @return array routes collected for every plugin */ $result = wa()->event('routing', $routes); $all_plugins_routes = array(); foreach ($result as $plugin_id => $routing_rules) { if ($routing_rules) { $plugin = str_replace('-plugin', '', $plugin_id); if ($url_type == 0) { $routing_rules = $routing_rules[0]; } else { $routing_rules = $routing_rules[1]; } foreach ($routing_rules as $url => &$route) { if (!is_array($route)) { list($route_ar['module'], $route_ar['action']) = explode('/', $route); $route = $route_ar; } $route['plugin'] = $plugin; $all_plugins_routes[$url] = $route; } unset($route); } } $routes = array_merge($all_plugins_routes, $routes); return $routes; }