示例#1
0
文件: admin.php 项目: kidaa30/Swevers
 public static function show()
 {
     use_library('navstack');
     FW4_Structure::check_structure();
     FW4_User::$include_superadmin = true;
     $language_codes = array_keys(languages());
     Router::set_language(array_shift($language_codes));
     View_Loader::get_instance()->set_path(BASEPATH . 'admin/');
     return self::route();
 }
示例#2
0
 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;
 }
示例#3
0
文件: site.php 项目: kidaa30/Swevers
 public static function reload_site()
 {
     $db = FW4_Db::get_instance();
     $site = false;
     if (!$site) {
         try {
             if (count(languages()) > 1) {
                 $query = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%');
                 $language_codes = array_keys(languages());
                 if ($countries = Config::countries()) {
                     $language_codes = array_keys($countries);
                 }
                 foreach ($language_codes as $code) {
                     $query->or_where('`url_' . $code . '` LIKE %s', $_SERVER['HTTP_HOST'] . '%');
                 }
                 $site = $query->get_row();
             } else {
                 $site = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%')->get_row();
             }
         } catch (PDOException $exception) {
             FW4_Structure::check_structure('', true);
         }
         if (!$site) {
             if (!($site = get_row('site'))) {
                 $name = str_ireplace('www.', '', $_SERVER['HTTP_HOST']);
                 $name = ucfirst(substr($name, 0, strpos($name, '.')));
                 $url = $_SERVER['HTTP_HOST'];
                 if (stristr(getcwd(), 'httpdocs')) {
                     $url .= substr(getcwd(), stripos(getcwd(), 'httpdocs') + strlen('httpdocs'));
                 }
                 insert('site', array("url" => $url, "name" => $name));
                 FW4_Structure::check_structure();
                 $site = where('url LIKE %s', $_SERVER['HTTP_HOST'])->get_row('site');
             } else {
                 $domain_handled = false;
                 // Process minisites
                 $types = FW4_Type_Manager::get_instance()->get_types();
                 foreach ($types as $typename => $type) {
                     if (method_exists($type, 'handle_domain')) {
                         if (!$site->structure_xml_expanded) {
                             FW4_Structure::check_structure("", true);
                             return self::reload_site();
                         }
                         $structure = new SimpleXMLElement($site->structure_xml_expanded);
                         $fields = $structure->xpath('//*[@type_name="' . $typename . '"]');
                         if (count($fields)) {
                             $prev = self::$current;
                             self::$current = $site;
                             if (call_user_func_array(array($type, 'handle_domain'), array($_SERVER['HTTP_HOST'], $fields))) {
                                 $domain_handled = true;
                                 break;
                             }
                             self::$current = $prev;
                         }
                     }
                 }
                 // Process subdomains
                 foreach (Config::subdomains() as $subdomain => $handler) {
                     //if () Router::set_content_prefix($handler);
                 }
                 if (!$domain_handled && $site->live) {
                     redirect((Config::https() ? 'https' : 'http') . '://' . $site->url . $_SERVER['REQUEST_URI']);
                 }
             }
         }
     }
     if (!$site->live && false === stristr($_SERVER['HTTP_HOST'], '.fw4.') && false === stristr($_SERVER['HTTP_HOST'], 'local')) {
         $db->query("UPDATE site SET live = 1 WHERE id = " . $site->id);
         if (stristr($site->url, '.fw4.be')) {
             where('id = %d', $site->id)->update('site', array('url' => $_SERVER['HTTP_HOST']));
         }
     }
     self::$current = $site;
     return $site;
 }