示例#1
0
 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;
 }
示例#2
0
                // Выходим из обработки, так как AJAX
            }
            define("URL", "page");
            if (!empty($url["url"]) && $url["url"] == ".html") {
                $url["url"] = $url["result"] . $url["url"];
            } else {
                $url["url"] = $url["without_home"];
            }
            define("APPLICATION_NAME", MAIN . "/" . $applications_store["template"][MAIN]);
            define("DIR", TEMPLATE . "applications/" . MAIN . "/" . $applications_store["template"][MAIN]);
            # определяем путь к директории приложения
            $api = new api(MAIN . "/" . $applications_store["template"][MAIN]);
            // создаём объект
            require_once PUBLIC_APPLICATIONS . MAIN . "/index.php";
            // подключаем
            $api->set("{HOME}", HOME);
        }
    }
}
# подключение модулей и плагинов
// ВРЕМЕННО НЕ РАБОТАЕТ
require_once PUBLIC_MODULES . "index.php";
#############################################
#   GLOBAL REPLACE IF NOT REPLASED
#############################################
$api->set("{DIR}", DIR);
$api->set("{TEMPLATE}", TEMPLATE);
$api->set("{MOD_DIR}", MOD_DIR);
$systems_scripts = '<link rel="stylesheet" href="' . TEMPLATE . 'system_library/css/jquery-ui.min.css">
' . "\t" . '<link rel="stylesheet" href="' . TEMPLATE . 'system_library/css/jquery-ui.theme.min.css">
' . "\t" . '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>