private function load_routes($file) { $routes = new Routes(); include_once SITE_PATH . "config/{$file}.php"; $routes->dump_to_file("{$file}"); $this->routing_tree =& $routes->routing_tree; }
public function testLoadRoutesNoAnything() { $_SERVER["QUERY_STRING"] = ""; $routes = new Routes(); $routes->analizeAndProcessRoutes(); $this->assertEquals("Application", $routes->controller); $this->assertEquals("Index", $routes->action); }
function testNestedRoutes() { $routes = new Routes(); $nested = $routes->resources("teams"); $nested->resources("ceva"); $routes->dump_to_file("nested"); include_once SITE_PATH . "config/nested.tmp.php"; $this->assertEqual($routes->routing_tree, $root); unlink(SITE_PATH . "config/nested.tmp.php"); }
public static function Run() { Logger::debug("Creating server object", "Server", "Run"); $router = new Routes(); $router->analizeAndProcessRoutes(); if ($router->controller && $router->action) { Logger::debug("Server controller: [" . $router->controller . "] action: [" . $router->action . "]", "Server", "Run"); $controller = $router->controller; $app = new $controller(); $app->params = $router->params; $app->controller = $router->controller; $app->action = $router->action; print $app->loadApp(); } }
public function render() { // Get Template and Page if (!file_exists(BASEPATH.'/app/views/'.Routes::getController().'/'.Routes::getMethod().'.php')) trigger_error('View file "'.Routes::getController().'/'.Routes::getMethod().'.php" was not found.'); Template::render($this->vars, true); }
/** * Appel statique de Router */ public static function __callStatic($method, $args) { if (is_null(self::$instance)) { self::$instance = new Router(); } return call_user_func_array([self::$instance, $method], $args); }
public static function render($vars, $displayContents = true) { // Get Templating Vars extract($vars, EXTR_SKIP); // Include Helper Functions require(BASEPATH.'/app/helpers/template.php'); // Render View File ob_start(); include(BASEPATH.'/app/views/'.Routes::getController().'/'.Routes::getMethod().'.php'); $contents = ob_get_contents(); ob_end_clean(); // Render Layout File ob_start(); include(BASEPATH.'/app/views/layouts/'.Routes::getController().'.php'); $view = ob_get_contents(); ob_end_clean(); foreach($templates as $key => $value) $view = str_ireplace($key, $value, $view); // Render View if ($displayContents) print $view; return $view; }
/** * Edit personnal information */ public function profile_edit($params) { $this->setView('profile_edit.php'); $this->setTitle(__('USER_EDIT_TITLE')); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); // Authorization if (!$is_student) { throw new ActionException('Page', 'error404'); } $user = User_Model::$auth_data; // Birthday $user['birthday'] = date(__('USER_EDIT_FORM_BIRTHDAY_FORMAT'), strtotime($user['birthday'])); // Saving data if (isset($_POST['mail']) && isset($_POST['msn']) && isset($_POST['jabber']) && isset($_POST['address']) && isset($_POST['zipcode']) && isset($_POST['city']) && isset($_POST['cellphone']) && isset($_POST['phone']) && isset($_POST['birthday'])) { try { // Other info $data = array('mail' => $_POST['mail'], 'msn' => $_POST['msn'], 'jabber' => $_POST['jabber'], 'address' => $_POST['address'], 'zipcode' => $_POST['zipcode'], 'city' => $_POST['city'], 'cellphone' => $_POST['cellphone'], 'phone' => $_POST['phone'], 'birthday' => $_POST['birthday']); $this->model->save((int) User_Model::$auth_data['id'], $data); Routes::redirect('student', array('username' => User_Model::$auth_data['username'])); } catch (FormException $e) { foreach ($data as $key => $value) { $user[$key] = $value; } $this->set('form_error', $e->getError()); } } $this->set('user', $user); $this->addJSCode('User.initEdit();'); }
function __construct($action = 'index', $recordId = null) { if (!$this->checkIsUser()) { Routes::redirect(); } switch ($action) { case 'index': $this->setAddressBookModel(); self::$data['action'] = $action; break; case 'add': self::$data['action'] = $action; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->addContact(); } break; case 'delete': self::$data['action'] = $action; $this->deleteContact($recordId); $this->setAddressBookModel(); break; case 'edit': self::$data['action'] = $action; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->addContact($_POST['id_contact']); } $this->setAddressBookModel((int) $recordId); break; } new Sidebar($this->sideMenuItems()); }
function __construct() { if (!$this->checkIsUser()) { Routes::redirect(); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $params = array(); $params['secret'] = '6Lf3ZxMTAAAAANVc5p92ISpeXZp8oTTrOr5WS6iD'; // Secret key if (!empty($_POST) && isset($_POST['g-recaptcha-response'])) { $params['response'] = urlencode($_POST['g-recaptcha-response']); } $params['remoteip'] = $_SERVER['REMOTE_ADDR']; $params_string = http_build_query($params); $requestURL = 'https://www.google.com/recaptcha/api/siteverify?' . $params_string; $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $requestURL)); $response = curl_exec($curl); curl_close($curl); $response = @json_decode($response, true); if ($response["success"] != true && !$this->checkIsUser()) { echo '<h3 class="alert alert-danger">Captcha - bład w weryfikacji</h3>'; } elseif ($response["success"] || self::$isLogged) { if ($this->addPost($_POST)) { header('Location: ' . parent::config()['url']); } } } else { $this->setPostModel(); } }
public static function StartApp() { ob_start('ob_gzhandler'); session_start(); // Defines define('BASEURL', substr((empty($_SERVER['HTTPS']) ? 'http://' : 'https://' ) . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'],0,-10)); define('BASEPATH', substr($_SERVER['SCRIPT_FILENAME'],0,-10)); // Helper Boot Loader require(BASEPATH.'/core/bootloader.php'); // Initialize Helpers BootLoader::loadHelpers(); Registry::getInstance(); // Handle Errors Registry::setDebugMode(true); set_error_handler('Template::handleError'); set_exception_handler('Template::handleException'); // Initialize Database Model::$db = DBO::getInstance('sqlite:example.sqldb'); // Init Autoloads spl_autoload_register('Autoload::controllers'); spl_autoload_register('Autoload::models'); // Determine Controllers and Methods Routes::getRoute(); // Run Application Routes::run(); }
public function goPage($page) { /* テンプレートファイルを取得 */ $theme = Configure::read('theme'); $template_path = THEME_DIR . $theme . '/'; if (!file_exists($template_path . 'Template.php')) { $template_path = LIB_DIR; } $template_class = 'Template'; if ($template_path == LIB_DIR) { $template_class = 'TemplateBase'; } require_once $template_path . $template_class . '.php'; /* ページを取得し、遷移する */ $page_routing = Routes::get(); $template = new $template_class($page_routing[$page]['php']); if (isset($page_routing[$page]['js'])) { if (is_array($page_routing[$page]['js'])) { $template->script_src += $page_routing[$page]['js']; } else { $template->script_src[] = $page_routing[$page]['js']; } } if (isset($page_routing[$page]['css'])) { if (is_array($page_routing[$page]['css'])) { $template->style_src += $page_routing[$page]['css']; } else { $template->style_src[] = $page_routing[$page]['css']; } } $template->render(); }
public static function create(array $routes = NULL) { if (self::$_instance === NULL) { self::$_instance = new self(); self::$_instance->routes = $routes; } return self::$_instance; }
public static function setRoutes() { // URL Routes Routes::add('/', 'apples', 'index'); Routes::add('/view/(:tofuID)/', 'apples', 'view'); Routes::add('/create/', 'apples', 'create'); Routes::add('/update/(:tofuID)/', 'apples', 'update'); Routes::add('/remove/(:tofuID)/', 'apples', 'remove'); }
public function initiateController() { if ($_SERVER['SCRIPT_FILENAME'] == './scripts/db.php') { return false; } $route = new Routes($this->uriSegment('whole')); $controller_class = $route->getController() . '_controller'; $action = $route->getAction(); if (class_exists($controller_class) && !empty($action)) { $controller = new $controller_class(); $controller->setParams($route->getParams($controller)); $controller->setRequest($route->getRequest()); $controller->{$action}(); } else { echo 'contorller: ' . $controller_class . ' action: ' . $action . '<br/>'; die("404 - dont know what you're looking for"); } }
function SearchFormView($arr_search_field, $arr_order_field, $arr_order_select, $url_options) { $form_search = '<form method="get" action="' . Routes::add_get_parameters($url_options, array()) . '">'; $form_search .= Utils::set_csrf_key(); $form_search .= I18n::lang('common', 'order_by', 'Order by') . ': ' . SelectForm('order_field', '', $arr_order_field) . ' ' . I18n::lang('common', 'in_order', 'By order') . ': ' . SelectForm('order_desc', '', $arr_order_select); $arr_order_field[0] = $_GET['search_field']; $form_search .= '<p>' . I18n::lang('common', 'search', 'Search') . ': ' . TextForm('search_word', '', $_GET['search_word']) . ' ' . I18n::lang('common', 'search_by', 'Search by') . ': ' . SelectForm('search_field', '', $arr_search_field) . '</p><p><input type="submit" value="' . I18n::lang('common', 'send', 'Send') . '"/> <input type="button" value="' . I18n::lang('common', 'reset', 'Reset') . '" onclick="javascript:location.href=\'' . $url_options . '\'"/>'; $form_search .= '</form></p>'; echo View::load_view(array(I18n::lang('common', 'order_and_search', 'Order and search'), $form_search), 'content'); }
/** * * @test */ public function itShouldDrawRoutes() { Routes::draw(function ($map) { $map->addRoute("test", ":controller/:action/:id"); $map->blog("blog/:action/:id"); }); $routes = Routes::getAllRoutes(); $this->expectsThat(count($routes))->shouldBe(2); var_dump($routes['blog'][0]); $this->expectsThat($routes['blog'][0])->shouldBe("blog/:action/:id"); }
/** * request_login * * @author Adrián Méndez <*****@*****.**> * @Version 1.0 */ public function request_login() { // Retifica el estatus de Login. if (!$this->Session->is_logged()) { // Si la acción actual no está permitida en $allowedUnloggedActions, redirecciona // a $loginAction if (!Routes::request_in_list($this->request, self::$allowedUnloggedActions)) { $this->go_to(self::$loginAction); } } }
public static function init() { // Carrega as variaveis de confiruracao para toda a aplicacao Configs::load(); // Define o modulo self::$moduleName = Routes::get('module'); // Define o controller self::setController(); // Define o metodo self::setMethod(); }
public static function getRoute() { self::$url = empty($_GET['url']) ? '/' : $_GET['url']; Routing::setRoutes(); if (empty(self::$controller)) trigger_error('Page Not Found'); elseif (!method_exists(self::$controller, self::$method)) trigger_error('Invalid Page Index'); Security::check(self::$controller, self::$method); return array(self::$controller, self::$method); }
public static function render($path, array $args = array()) { if (self::$_instance === NULL) { self::init(); } $args['request'] = Request::getInstance(); $args['static_url'] = Rivet::getInstance()->config['static_url']; $template = self::$_instance->twig->loadTemplate($path); $template->routes = Routes::getInstance(); self::$_instance->body = $template->render($args); return self::$_instance->body; }
function run() { $config = parse_ini_file('../.config'); $this->setUpDb(); $showErrors = isset($config['showErrors']) ? $config['showErrors'] : false; $configuration = ['settings' => ['displayErrorDetails' => $showErrors]]; $c = new \Slim\Container($configuration); // create new Slim instance $app = new \Slim\App($c); // create new Slim instance //$app = new \Slim\App(); $app->db = $this->database; $this->flashDB(false); $app->auth = false; $app->user = ''; $app->register = $config['registerActive']; $app->add(function ($request, $response, $next) use(&$app) { if (isset($_SESSION['userID'])) { $app->auth = true; $app->user = $_SESSION['username']; } $response = $next($request, $response); return $response; }); $container = $app->getContainer(); $container['view'] = function ($c) { // templates location and a settings array $view = new \Slim\Views\Twig('../templates', ['cache' => '../cache', 'auto_reload' => true, 'debug' => true]); // Instantiate and add Slim specific extension $view->addExtension(new Slim\Views\TwigExtension($c['router'], $c['request']->getUri())); return $view; }; $route = new Routes($app); $app = $route->run($app); $this->app = $app; // Run app $this->app->run(); }
function __construct($mode, $action = null) { if (!$this->isAdmin()) { Routes::redirect(); } self::$data['mode'] = $mode; if ($action && isset($action['action'])) { $functionToFire = $action['action'] . ucfirst($mode); if (isset($action['id'])) { self::$data['action'] = $action['action']; $this->{$functionToFire}($action['id']); } else { self::$data['action'] = $action['action']; $this->{$functionToFire}(); } } $this->{$mode}(); }
public function dispatch() { if (self::$_instance === NULL) { self::getInstance(); } $routes = Routes::getInstance(); $route = $routes->match(); if ($route) { $view = $route->run(); if ($view instanceof Response) { self::$_instance->response = $view; } // allow returning a response straight from the view self::$_instance->response = new Response($view); return self::$_instance->response; } return notfound(); }
public static function dispatch($url, $controller, $action) { if (Settings::getItem('fancyurl') == true) { $a_params = Routes::getParams($url); if ($a_params !== false) { foreach ($a_params as $param => $value) { $_GET[$param] = $value; } } } $controller_dispatch = new $controller(); $return = $controller_dispatch->{$action}(); if (isset($_GET["json"]) and $_GET["json"] == 1) { die(json_encode(utf8_encode($return))); } elseif (isset($_GET["ajax"]) and $_GET["ajax"] == 1) { die(utf8_encode($return)); } }
/** * Execute la commande d'affichage des routes de l'application * @return string */ public function executeCommand() { // récupération des routes de l'application require_once ROOT_DIR . '/app/routes.php'; $cadrecell = '+' . str_repeat("-", $this->lencell) . '+' . str_repeat("-", $this->lencellmethod) . '+' . str_repeat("-", $this->lencellalias) . '+' . str_repeat("-", $this->lencell) . '+' . "\n"; echo $cadrecell; echo '| URL ' . str_repeat(" ", $this->lencell - 5) . '| METHOD ' . str_repeat(" ", $this->lencellmethod - 8) . '| ALIAS ' . str_repeat(" ", $this->lencellalias - 7) . '| CALL ' . str_repeat(" ", $this->lencell - 6) . '|' . "\n"; echo $cadrecell; foreach (\Routes::getRoutes() as $method => $routes) { foreach ($routes as $route) { echo '| ' . $route->getPath() . str_repeat(' ', $this->lencell - strlen($route->getPath()) - 1); echo '| ' . $method . str_repeat(' ', $this->lencellmethod - strlen($method) - 1); echo '| ' . $route->getAlias() . str_repeat(' ', $this->lencellalias - strlen($route->getAlias()) - 1); echo '| ' . $route->getCallable() . str_repeat(' ', $this->lencell - strlen($route->getCallable()) - 1) . '|' . "\n"; } } echo $cadrecell; exit; }
public function create_route() { $route_string = $this->containing_post_type . "/:name/" . $this->contained_post_type; \Routes::map($route_string, function ($params) { $posts = get_posts(array('name' => $params['name'], 'post_type' => $this->containing_post_type)); if ($posts) { $wp_post = $posts[0]; $query = array('post_type' => $this->contained_post_type, 'connected_type' => $this->p2p_connection_type, 'connected_items' => $wp_post->ID); } $params += array('archive_title' => $this->get_archive_title_string($wp_post, $this->contained_post_type), 'containing_post_type' => $this->containing_post_type, 'contained_post_type' => $this->contained_post_type, 'p2p_connection_type' => $this->p2p_connection_type); \Routes::load($this->template, $params, $query, 200); }); $paginated_route_string = $this->containing_post_type . "/:name/" . $this->contained_post_type . "/page/:pg"; \Routes::map($paginated_route_string, function ($params) { $posts = get_posts(array('name' => $params['name'], 'post_type' => $this->containing_post_type)); if ($posts) { $wp_post = $posts[0]; $query = array('post_type' => $this->contained_post_type, 'connected_type' => $this->p2p_connection_type, 'connected_items' => $wp_post->ID, 'paged' => $params['pg']); $params += array('archive_title' => $this->get_archive_title_string($wp_post, $this->contained_post_type), 'containing_post_type' => $this->containing_post_type, 'contained_post_type' => $this->contained_post_type, 'p2p_connection_type' => $this->p2p_connection_type); } \Routes::load($this->template, $params, $query, 200); }); }
public function run() { if (strpos($_SERVER["REQUEST_URI"], "?")) { $a_request_uri = explode("?", $_SERVER["REQUEST_URI"]); $request_uri = $a_request_uri[0]; } else { $request_uri = $_SERVER["REQUEST_URI"]; } $request_uri = explode(Settings::getItem('webroot'), $request_uri); $route = Routes::getByUrl(Routes::getRealPathOfRequest($request_uri[1])); if (Routes::verifyRoute($request_uri[1])) { if (Settings::getItem('authentication') === true and Auth::verifyControllerAuth($route["controller"], $route["action"])) { if (Auth::verifyAuth()) { Dispatch::dispatch($request_uri[1], $route["controller"] . "Controller", $route["action"]); } else { foreach (Routes::getParse() as $route) { if (array_key_exists('behavior', $route)) { if ($route["behavior"] == "login") { Routes::httpRedirect(Routes::getUrlByName($route["name"])); } } } } } else { Dispatch::dispatch($request_uri[1], $route["controller"] . "Controller", $route["action"]); } } else { foreach (Routes::getParse() as $route) { if (array_key_exists('behavior', $route)) { if ($route["behavior"] == "404") { Routes::httpRedirect(Routes::getUrlByName($route["name"])); } } } } }
/** * Create a Routes object * * @return Routes * @author Justin Palmer */ function __construct() { self::$Hash = new RoutesHash(); }
public function resolve($link) { return Routes::detail($link->getId(), $link->getSlug(), Prismic::context()->getRef()); }