/** * @param string $value */ public function set_language($value) { if (Request::get_var('language')) { setcookie('language', $value, strtotime('+10 years'), '/'); } else { $this->set_params(['language' => $value], 'configuration'); } }
public function navigate(PageModel $page, $params) { if (strpos(Request::uri(), 'admin_panel') !== false) { (new AdminPanelActionRouter())->navigate($page, $params); } else { (new SiteActionRouter())->navigate($page, $params); } }
private function check_request_method($value) { switch (strtolower($value)) { case 'ajax': return Request::is_ajax(); case 'post': return Request::is_post(); case 'get': return Request::is_get(); default: return false; } }
private function get_route() { $request_uri = Request::uri(); if (isset($this->routes[$request_uri])) { return $this->routes[$request_uri]; } else { $keys = array_keys($this->routes); foreach ($keys as $key) { if (strpos($key, ':') !== false) { $parts = explode('/', $key); $parts_keys = array_keys($parts); foreach ($parts_keys as $part_key) { $part = $parts[$part_key]; $pos = strpos($part, ':'); if ($pos !== false) { $sub_str = substr($part, $pos + 1); switch ($sub_str) { case 'number': $parts[$part_key] = str_replace([$sub_str, ':'], ['(\\d+)', ''], $part); break; case 'string': default: $parts[$part_key] = str_replace([$sub_str, ':'], ['(\\w+)', ''], $part); break; } } } $parts = implode('\\/', $parts); preg_match_all("/^{$parts}\$/iU", $request_uri, $result, PREG_SET_ORDER); if (!empty($result[0]) && count($result)) { $this->route_params = array_slice($result[0], 1); return $this->routes[$key]; } } } foreach ($keys as $key) { if (strpos($key, '*') !== false) { return $this->routes[$key]; } } return null; } }
protected function show_result(GetResponse $response) { /** * @var $template Template */ $template = Application::get_class(\Starter::class); $smarty = new \Smarty(); $bundle_file = ROOT_PATH . DS . 'static_builder' . DS . 'bundle.result.json'; $bundle_result = json_decode(file_get_contents($bundle_file), true); $smarty->assign('bundle_result', $bundle_result); if (strpos(Request::uri(), 'admin_panel') !== false) { $smarty->setTemplateDir($template->get_path() . DS . 'templates' . DS . 'admin_panel'); } else { $smarty->setTemplateDir($template->get_path() . DS . 'templates' . DS . 'site'); } $smarty->setCompileDir($template->get_path() . DS . 'templates_c'); $smarty->assign($response->blocks); $smarty->assign('title', new PageTitle()); echo $smarty->getTemplate('index' . DS . 'index.tpl.html'); }
/** * common\classes\Request::is_token_valid */ public function test_is_token_valid() { $_GET['token'] = md5(uniqid('token', true)); self::assertFalse(Request::is_token_valid()); }
public function render() { $this->assign('uri', Request::uri()); return $this->get_template($this->template_name); }
private function action_delete_user() { /** * @var $user \User */ $user = Application::get_class(\User::class); $mapper = $user->get_mapper(); $mapper->delete($mapper->find_by_id(Request::get_var('id', 'int', 0))); $this->response->status = 'success'; /** * @var $template \Starter */ $template = Application::get_class(\Starter::class); /** * @var $lang_vars \ArrayAccess */ $lang_vars = new LanguageFile('routers' . DS . 'router.json', $template->get_lang_path()); $this->response->message = $lang_vars['messages']['user_deleted']; }
private function load_data() { $file = ROOT_PATH . DS . 'resource' . DS . CURRENT_LANG . '_titles.json'; $area = strpos(Request::uri(), 'admin_panel') === false ? 'site' : 'admin_panel'; $this->titles = json_decode(file_get_contents($file), true)[$area]; }
public function get_data() { return ['url' => Request::uri()]; }