function glob_pattern($pattern, $segments = NULL) { if ($segments === NULL) { $segments = segments(); } list($dir, $path) = explode('/', $pattern, 2); return '{' . implode('/,', glob_packages()) . '/}' . $dir . '/{' . implode('/,}{', $segments) . '/,}' . $path; }
function r_href($path = NULL, $protocol = NULL, $hidden = FALSE) { // パスから引数を取得 $args = $path === NULL ? [] : explode('/', trim($path, '/')); // ルーティングされたセグメントをデフォルトセグメントとして擬似ルーティング $segments = route($args, segments()); // デフォルトセグメントを削除 foreach ($segments as $key => $value) { if ($value === default_segments()[$key]) { unset($segments[$key]); } } return href(implode('/', array_merge($segments, $args)), $protocol, $hidden); }
function routePath() { $flag = FALSE; $rsaquo = " ›› "; $path = path(whichApplication()); if (segments() > 0) { for ($i = 0; $i <= segments() - 1; $i++) { if (!$flag) { if (segments() === 6) { $flag = TRUE; $HTML = a(__(_("Home")), PATH("cpanel")) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(2)))), $path . segment(2)) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3)) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(4)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4)) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(5)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4) . _sh . segment(5)); } elseif (segments() === 5) { $flag = TRUE; $HTML = a(__(_("Home"), path("cpanel"))) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(2)))), $path . segment(2)) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3)) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(4)))), $path . segment(2) . _sh . segment(3) . _sh . segment(4)); } elseif (segments() === 4) { $flag = TRUE; $HTML = a(__(_("Home")), path("cpanel")) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(1)))), $path . "cpanel") . $rsaquo; $HTML .= a(__(_(ucfirst(segment(3)))), $path . segment(2) . _sh . segment(3)); } elseif (segments() === 3) { $flag = TRUE; $HTML = a(__(_("Home")), path("cpanel")) . $rsaquo; $HTML .= a(__(_(ucfirst(segment(1)))), $path . segment(3)); } elseif (segments() === 2) { $flag = TRUE; $HTML = a(__(_("Home")), path("cpanel")); } else { $HTML = a(__(_("Home")), path("cpanel")); } } } } return $HTML; }
?> </a> <button class="mobile-menu"> <span>toggle menu</span> </button> <nav role="navigation"> <ul> <li class="<?php echo segment(0) == 'offer' && in_array('te-koop', segments()) ? 'selected' : ''; ?> "><a href="<?php echo url('te-koop'); ?> ">te koop</a></li> <li class="<?php echo segment(0) == 'offer' && in_array('te-huur', segments()) ? 'selected' : ''; ?> "><a href="<?php echo url('te-huur'); ?> ">te huur</a></li> <li class="<?php echo segment(0) == 'projects' ? 'selected' : ''; ?> "><a href="<?php echo url('nieuwbouw'); ?> ">nieuwbouw</a></li> </ul> <ul> <li class="<?php
private static function route($priority) { $uri = implode('/', segments()); foreach (self::$slugs as $key => $routes) { $key = str_replace('%s', '([a-z0-9\\-]+)', str_replace('%d', '([0-9]+)', str_replace('/', '\\/', $key))); if (preg_match('/^' . $key . '(\\/|$)/is', $uri, $matches)) { array_pop($matches); array_shift($matches); foreach ($routes as &$route) { if ($route->get_priority() == $priority) { $arguments = preg_replace('/^' . $key . '(\\/|$)/is', '', $uri); $arguments = explode("?", $arguments); $arguments = array_filter(explode("/", array_shift($arguments))); $arguments = array_merge($matches, $arguments); // Check if the class that will handle the content actually contains the requested function. if (!method_exists($route->get_classname(), $route->get_function())) { continue; } // Check if we're not calling said function with too few parameters. $reflector = new ReflectionClass($route->get_classname()); if (count($arguments) < $reflector->getMethod($route->get_function())->getNumberOfRequiredParameters()) { continue; } // Check if this function might want variable number of parameters. $collapse_parameters = false; $parameters = $reflector->getMethod($route->get_function())->getParameters(); if (count($parameters) && end($parameters)->name == 'parameters') { $collapse_parameters = true; } if (count($arguments) > count($parameters) && $collapse_parameters && $priority == ROUTE_DEFAULT) { $route->set_priority(ROUTE_LATE); continue; } // Check if we're not calling said function with too many parameters. if (count($arguments) > count($parameters) && !$collapse_parameters) { continue; } // Check if we're not calling a static function. if ($reflector->getMethod($route->get_function())->isStatic()) { continue; } // Save old segments should we need it again later self::$urlsegments = self::$segments; // Set the segments to those that matched our content self::$segments = array(); self::$segments[0] = strtolower($route->get_contentname()); self::$segments[1] = strtolower($route->get_function()); self::$segments = array_merge(self::$segments, $arguments); // Set the current route self::$current_route = $route; // Check database if needed (only do this when there's no admin panel) if (!Config::admin_enabled()) { $site = current_site(); if (self::is_fw4() && !$site->live) { FW4_Structure::check_structure(); } } // Fire the controller View_Loader::get_instance()->set_path(CONTENTPATH . self::$content_prefix . self::$segments[0]); $page = self::$content_pages[strtolower($route->get_classname())]; if ($collapse_parameters) { $non_optional = array_splice($arguments, 0, count($parameters) - 1); $arguments = array_merge($non_optional, array(array_diff($arguments, array('index')))); } try { $result = call_user_func_array(array($page, $route->get_function()), $arguments); } catch (RowNotFoundException $e) { $result = false; } // If the controller returns false, reset the segments and continue matching if ($result === false) { self::$segments = self::$urlsegments; continue; } return true; } } } } return false; }
private static function route() { // Set the PHP locale to correspond to our defined language. if (language() == 'en') { setlocale(LC_ALL, 'en_US'); } else { if (language() == 'nl') { setlocale(LC_ALL, 'nl_BE'); } else { if (language() == 'fr') { setlocale(LC_ALL, 'fr_FR'); } else { if (language() == 'de') { setlocale(LC_ALL, 'de_DE'); } } } } // Show the login page if requested if (segment(0) == 'login') { return self::login(); } // Show the forgot pass page if requested if (segment(0) == 'forgot') { return self::forgotpass(); } // Show the forgot pass page if requested if (segment(0) == 'reset-password' && strlen(segment(1)) > 24 && ($user = where('password_code = %s', segment(1))->get_row('user'))) { return self::resetpass($user); } // Rebuild search index if requested if (segment(0) == 'rebuild_search_index') { FW4_Structure::rebuild_search_index(); redirect(url(ADMINDIR, false)); } // User should be logged in. If not, demand login. if (!FW4_User::is_logged_in()) { redirect(url(ADMINDIR . '/login', false)); } // User is logged in. Make sure he's an admin. if (!FW4_User::is_admin()) { FW4_User::log_out(); redirect(url(ADMINDIR . '/login', false)); } // Log out if requested if (segment(0) == 'logout') { FW4_User::log_out(); redirect(url(ADMINDIR . '/login', false)); } // If not viewing any specific page. Redirect to the first one. // If at some point we'd like to implement a dashboard, this would be the place to show it. if (!count(segments())) { $pages = self::get_pages(); $page = array_shift($pages); redirect(url(ADMINDIR . '/' . $page['name'], false)); } // If the user is viewing a special page (like a popup), show it. if (substr(segment(0), 0, 1) == '_' && file_exists(BASEPATH . 'admin/special/' . substr(segment(0), 1) . '.php')) { include BASEPATH . 'admin/special/' . substr(segment(0), 1) . '.php'; return true; } // Check if this is an AJAX request. if (substr(segment(0), 0, 5) == 'ajax_') { $segments = segments(); call_user_func_array(get_class() . '::' . array_shift($segments), $segments); return true; } return self::handle_item(segments()); }
/** * getURL * * Returns and URL built with _webBase and the Amount of segments contained on route() * * @return array */ function getURL() { global $ZP; $URL = NULL; for ($i = 0; $i <= segments() - 1; $i++) { if ($i === segments() - 1) { $URL .= segment($i); } else { $URL .= segment($i) . "/"; } } $URL = get("webBase") . "/{$URL}"; return $URL; }