public function action_edit($role_id = 0) { $role_id = intval($role_id); if ($role_id <= 0) { Request::instance()->redirect('/admin/role/index'); } $role = BLL_Role::getById($role_id); if (!$role) { Request::instance()->redirect('/admin/role/index'); } $data = array(); if (Request::$method == "POST") { if (intval($_POST['role_id']) != $role_id) { Request::instance()->redirect('/admin/role/index'); } $post = $role->validate_update($_POST); if ($post->check()) { $post_values = $post->as_array(); $role->name = $post_values['name']; $role->description = $post_values['description']; $role->save(); Request::instance()->redirect('/admin/role/index'); } else { $_POST = $post->as_array(); $data['errors'] = $post->errors('admin/role/form'); } } $this->template->title = __("Sửa nhóm tài khoản"); $this->template->section_title = __("Sửa nhóm tài khoản"); $data['role'] = $role; $this->template->content = View::factory('admin/role/edit', $data); }
public function createFirstUser() { $request = \Request::instance(); $method = $request->method(); if (Verbs::GET === $method) { if (!User::adminExists()) { $data = ['version' => \Config::get('df.api_version'), 'email' => '', 'name' => '', 'first_name' => '', 'last_name' => '']; return view('firstUser', $data); } else { return redirect()->to('/'); } } else { if (Verbs::POST === $method) { $data = $request->all(); $registrar = new Registrar(); $validator = $registrar->validator($data); if ($validator->fails()) { $errors = $validator->getMessageBag()->all(); $data = array_merge($data, ['errors' => $errors, 'version' => \Config::get('df.api_version')]); return view('firstUser', $data); } else { $registrar->create($data); return redirect()->to('/'); } } } }
public function action_add_to_controller($controller_id) { $data = array(); $this->template->title = 'Manage action in Controller'; $data['controller'] = $controller = Model_SysController::getSysControllerToArray($controller_id); if ($_POST) { $_sysA = new Model_Action(); $post = $_sysA->validate_create($_POST); if ($post->check()) { //$_sysA->values($post); $_post = $post->as_array(); unset($post); $_sysA->name = $_post['name']; $_sysA->description = $_post['description']; //$controller = new Model_SysController($controlder_id); $_sysA->controller = $controller; $_sysA->save(); Request::instance()->redirect('sysaction/in_controller/' . $controller_id); } else { $data['errors'] = $post->errors('sysaction/add_to_controller/' . $controller_id); #Repopulate $_POST data $_POST = $post->as_array(); } } $view = View::factory('racl/sysaction/add_to_controller', $data); $this->template->content = $view->render(); }
public static function getInstance() { if (self::$instance === false) { self::$instance = new Request(); } return self::$instance; }
public static function parse() { $resources = Config::get('resource'); $resource = null; $resource_uri = parse_url($_SERVER['REQUEST_URI']); $resource_uri = str_replace('/index.php', '', $resource_uri['path']); $request = Request::instance(); foreach ($resources as $key => $val) { preg_match('#' . $key . '#', $resource_uri, $matches); if (!empty($matches[0])) { $resource = $val; foreach ($matches as $k => $match) { if (!is_int($k)) { $request->set_data($k, $match); } } break; } } if (!empty($resource)) { require_once RESOURCE_PATH . $resource . '.php'; } else { throw new Route_Exception('resource not found: ' . $resource_uri); } return $resource; }
static function getInstance() { if (self::$instance === null) { self::$instance = new Request(); } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Request(); } return self::$instance; }
public function action_add() { $this->template->title = 'Add Role'; //print_r($data['roles']); $data = array(); if ($_POST) { $role = new Model_Role(); $post = $role->validate_create($_POST); if ($post->check()) { $values = $post->as_array(); unset($post); $role->name = $values['name']; $role->description = $values['description']; $role->save(); Request::instance()->redirect('role/index'); } else { #Get errors for display in view $data['errors'] = $post->errors('racl/role/add', TRUE); #Repopulate $_POST data $_POST = $post->as_array(); } } // $this->template->content = View::factory('racl/role/add', $data); }
private function addAward() { $success = true; $errors = array(); $data = Arr::merge($this->sanitize($_POST), $_FILES); Upload::$default_directory = Kohana::config('myshot.basePath'); if ($stage_path = Upload::save($data['photo'])) { $award = $this->site->createAward($this->sanitize($data['name']), $data); foreach ($this->site->imageTypes as $imageType) { $name = $imageType->name; if ($name == self::FULL) { Library_Akamai::factory()->addToDir($stage_path, Kohana::config('akamai.honordir')); $award->addImage(self::FULL, $this->webPath($stage_path)); } else { if (ImageTypes::types()->{$name}) { $resized = $this->resizeHonor($stage_path, ImageTypes::types()->{$name}->size); $award->addImage($name, $this->webPath($resized)); } } } } else { $success = false; $errors[] = "Image failed to load."; } if ($success) { Message::set(Message::SUCCESS, 'You have successfully added an award.'); Request::instance()->redirect('admin/awards'); } else { Message::set(Message::ERROR, Arr::flatten($errors)); } }
public function action_create() { $this->template->title = __("Thêm mới kênh truyền hình"); $this->template->section_title = __("Thêm mới kênh truyền hình"); $data = array(); if (Request::$method == "POST") { $channel = new LichTruyenHinh(); $post = $channel->validate_create($_POST); if ($post->check()) { $post = $post->as_array(); $channel->user_id = Auth::instance()->get_user()->id; $channel->channel_name = $post['channel_name']; $channel->active = true; $channel->slug = $post['slug']; $channel->meta_keys = $post['meta_keys']; $channel->meta_desc = $post['meta_desc']; $channel->xml_uri = $post['xml_uri']; $channel->created_at = date("Y-m-d h:i:s"); $channel->save(); Message::success('Thêm mới kênh truyền hình thành công!'); Request::instance()->redirect('/admin/lichtruyenhinh/index'); } else { $_POST = $post->as_array(); $data['errors'] = $post->errors(); } } // $categories = TruyenCuoiCategory::bll()->getCatById_WithStoryCount(); // $data['categories'] = $categories; $this->template->content = View::factory('/admin/lichtruyenhinh/create', $data); }
public static function initialize($path) { Config::setPath($path . 'config/'); self::$request = Request::instance(); self::$config = Config::instance(); self::$store = Store::instance(); }
public function action_authorize() { if ($this->token and $this->token->token !== Arr::get($_GET, 'oauth_token')) { // Delete the token, it is not valid Cookie::delete($this->cookie); // Send the user back to the beginning Request::instance()->redirect($this->request->uri(array('action' => 'index'))); } // Get the verifier $verifier = Arr::get($_GET, 'oauth_verifier'); // Store the verifier in the token $this->token->verifier($verifier); // Exchange the request token for an access token $this->token = $this->provider->access_token($this->consumer, $this->token); // Store the access token Cookie::set($this->cookie, serialize($this->token)); // At this point, we need to retrieve a unique twitter id for the user. $response = OAuth_Request::factory('resource', 'GET', 'http://api.twitter.com/1/account/verify_credentials.json')->param('oauth_consumer_key', Kohana::config('oauth.twitter.key'))->param('oauth_token', $this->token)->sign(OAuth_Signature::factory('HMAC-SHA1'), $this->consumer, $this->token)->execute(); $response = json_decode($response); $twitter_id = $response->screen_name; $user = ORM::factory('user')->where('username', '=', $twitter_id)->find(); !$user->id and Request::instance()->redirect('/auth/confirm?id=' . $twitter_id); Auth::instance()->force_login($user); Session::instance()->set('notification', 'Succesfully logged in.'); Request::instance()->redirect('/'); }
public static function render(array $vars = array(), array $globals = array(), $file = false, array $options = array()) { if (isset($vars['_data'])) { $data = $vars['_data']; } else { $data = array(); $config = Kohana::config('render'); $expose = isset($config['json_expose']) ? $config['json_expose'] : (isset($config['expose']) ? $config['expose'] : array()); foreach ($expose as $var) { if (isset($vars[$var])) { $data[$var] = $vars[$var]; } } } if (empty($vars['_no_header']) && (!empty(Request::$is_ajax) || !empty($vars['_force_header']))) { // only send json if it is an XMLHttpRequest (subject to overrides) Request::instance()->headers['Content-Type'] = 'application/json'; $result = json_encode($data); } elseif (empty($vars['_plain'])) { // if we are sending it as HTML we probably want this $result = htmlspecialchars(json_encode($data)); } else { // unless we are sure! $result = json_encode($data); } return $result; }
public function action_categories() { // Get the category model $categories = Jelly::select('category'); /* * If the route is something like this: categories/alias-of-category/2, * then we know that we're accessing the children of "alias-of-category" but display is limited to 2 levels only */ $category = $this->request->param('category', NULL); $category = Jelly::select('category', $category); $limit = $this->request->param('limit', $this->params->get('maxLevel', -1)); if ($category->loaded()) { // Get the children of the category $categories->where('parent_id', '=', $category->id); } else { // Just get all the 1st Level Categories $categories->where('level', '=', 1); } // Set the result in the View $items = View::factory('categories/list')->set('categories', $categories->execute())->set('limit', $limit)->set('level', 1)->render(); // If this is an internal HMVC call, then we don't need to display the template which displays the headings if (Request::instance() !== Request::current()) { $this->request->response = $items; return; } // Combine the 2 views, this view loads the Title and Description, then inserts the previous view "items" above $this->request->response = View::factory('categories/template')->set('items', $items)->set('page_heading', $this->params->get('page_title'))->render(); }
/** * Singleton initiator * * @return Request */ public static function &getInstance() { if (empty(self::$instance)) { self::$instance = new Request(); } return self::$instance; }
/** * Visualiza la página tras la grabación de la petición y vuelca los * mansajes de error en caso de que existan. * * @return \Illuminate\Http\Response */ public function index() { //Variable para retornar los datos resultantes de la gestión del formulario $resultado = null; //Volcamos los datos del formulario en una variable y usamos el validador de la //clase para validar los datos. $request = \Request::instance(); $validacion = Peticion::validar($request); if ($validacion->fails()) { //Comunicación de errores en caso de que no esté correcto el formulario $resultado = redirect()->back()->withInput()->withErrors($validacion->errors()); } elseif ($this->store($request, auth()->user()->cod_usuario)) { //Si la validación es buena, y la grabación se realiza bien, enviamos un correo al //administrador del sitio como aviso de que tiene unapetición nueva. $asunto = 'Nuevo mensaje de usuario Giftfinder'; $mensaje = '<br/>Email usuario: ' . $request->email_respuesta . '<br/>Asunto: ' . $request->asunto . '<br/>Mensaje: ' . $request->mensaje; //Si no indicamos esta cabecera, no inerpretará el código html y no saldrán //los acentos ni las ñ correctamente: $cabecera = 'Content-type: text/html; charset=utf-8'; //En vez de rociodemula@demosdata.com, se podría enviar a un buzón especifico del //sitio, o al correo de todos los administradores de la tabla Usuarios. $correo = mail('*****@*****.**', $asunto, $mensaje, $cabecera); //Devolvemos el resultado de éxito y el resultado del envío de correo a la vista. $resultado = view('contact', ['exito' => true, 'correo' => $correo]); } else { //Si ha fallado la grabación en la tabla Peticiones, preparamos el resultado para //que la vista lance el mensaje de error. $resultado = view('contact', ['exito' => false, 'correo' => false]); } return $resultado; //El resultado se devuelve de igual forma. }
public static function instance(&$uri = TRUE) { if (!Request::$instance) { if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) { Request::$protocol = 'https'; } if (isset($_SERVER['REQUEST_METHOD'])) { Request::$method = $_SERVER['REQUEST_METHOD']; } if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { Request::$is_ajax = TRUE; } Request::$client_ip = self::get_client_ip(); if (Request::$method !== 'GET' and Request::$method !== 'POST') { parse_str(file_get_contents('php://input'), $_POST); } if (isset($_SERVER['HTTP_USER_AGENT'])) { Request::$user_agent = $_SERVER['HTTP_USER_AGENT']; } if (isset($_SERVER['HTTP_REFERER'])) { Request::$referrer = $_SERVER['HTTP_REFERER']; } if ($uri === TRUE) { $uri = Request::detect_uri(); } $uri = preg_replace('#//+#', '/', $uri); $uri = preg_replace('#\\.[\\s./]*/#', '', $uri); Request::$instance = new Request($uri); } return Request::$instance; }
public function receive() { $request = \Request::instance(); if (!$this->goCardless->validateWebhook($request->getContent())) { return \Response::make('', 403); } $parser = new \BB\Services\Payment\GoCardlessWebhookParser(); $parser->parseResponse($request->getContent()); switch ($parser->getResourceType()) { case 'bill': switch ($parser->getAction()) { case 'created': $this->processNewBills($parser->getBills()); break; case 'paid': $this->processPaidBills($parser->getBills()); break; default: $this->processBills($parser->getAction(), $parser->getBills()); } break; case 'pre_authorization': $this->processPreAuths($parser->getAction(), $parser->getPreAuthList()); break; case 'subscription': $this->processSubscriptions($parser->getSubscriptions()); break; } return \Response::make('Success', 200); }
/** * @param string $clientId * @param string $clientSecret * @param string $redirectUrl */ public function __construct($clientId, $clientSecret, $redirectUrl) { /** @var Request $request */ $request = \Request::instance(); $serverConfig = ['identifier' => $clientId, 'secret' => $clientSecret, 'callback_uri' => $redirectUrl]; parent::__construct($request, new TwitterServer($serverConfig)); }
function is_grip_proxied() { if (\Request::instance()->grip_proxied) { return true; } return false; }
public function before() { parent::before(); // The user is already logged in if (Auth::instance()->logged_in()) { Request::instance()->redirect(''); } // Load the configuration for this provider $config = Kohana::config('oauth.'.$this->provider); // Create a consumer from the config $this->consumer = OAuth_Consumer::factory($config); // Load the provider $this->provider = OAuth_Provider::factory($this->provider); if ($token = Cookie::get($this->cookie)) { // Get the token from storage $this->token = unserialize($token); } }
public static function key($key, $default = NULL) { $uri = Request::instance()->uri(); // check $_GET array for key set if (isset($_GET[$key])) { $value = $_GET[$key]; } // check $_POST array for key set if (isset($_POST[$key])) { $value = $_POST[$key]; } // if not set in _GET or _POST if (!isset($_GET[$key]) and !isset($_POST[$key])) { // check if set in _SESSION if (Session::instance()->get($uri . '-' . $key)) { $value = Session::instance()->get($uri . '-' . $key); } else { $value = $default; } } // Set _SESSION Session::instance()->set($uri . '-' . $key, $value); // Return Value return $value; }
/** * The before() method is called before your controller action. * In our template controller we override this method so that we can * set up default values. These variables are then available to our * controllers if they need to be modified. */ public function before() { //Run any before if needed parent::before(); //Open session $this->session = Session::instance(); //Check user auth and role $action_name = Request::instance()->action; if (is_array($this->secure_actions) && array_key_exists($action_name, $this->secure_actions) && Auth::instance()->logged_in($this->secure_actions[$action_name]) === FALSE) { if (Auth::instance()->logged_in()) { Request::instance()->redirect('admin/site/noaccess'); } else { Request::instance()->redirect('admin/site/signin'); } } if ($this->auto_render) { // Initialize empty values $this->template->title = ''; $this->template->meta_keywords = ''; $this->template->meta_description = ''; $this->template->meta_copywrite = ''; $this->template->header = ''; $this->template->content = ''; $this->template->footer = ''; $this->template->styles = array(); $this->template->scripts = array(); $this->template->section_title = ' '; } }
/** * Sets up db by running migration and seeder. * * @return \Illuminate\Http\RedirectResponse */ public function setupDb() { if (\Cache::get('setup_db', false)) { $request = \Request::instance(); $method = $request->method(); if (Verbs::GET === $method) { return view('setup', ['version' => config('df.version')]); } else { if (Verbs::POST === $method) { try { if (\Cache::pull('setup_db', false)) { \Artisan::call('migrate', ['--force' => true]); \Artisan::call('db:seed', ['--force' => true]); if ($request->ajax()) { return json_encode(['success' => true, 'redirect_path' => '/setup']); } else { return redirect()->to('/setup'); } } else { if ($request->ajax()) { return json_encode(['success' => false, 'message' => 'Setup not required. System is already setup']); } } } catch (\Exception $e) { if ($request->ajax()) { return json_encode(['success' => false, 'message' => $e->getMessage()]); } else { return view('errors.generic', ['error' => $e->getMessage(), 'version' => config('df.version')]); } } } } } return redirect()->to('/'); }
public function before() { parent::before(); $this->session = Session::instance(); # Check user authentication $auth_result = true; $action_name = Request::instance()->action; if (array_key_exists($action_name, $this->auth)) { $auth_result = $this->_check_auth($action_name); } else { if (array_key_exists('*', $this->auth)) { $auth_result = $this->_check_auth('*'); } } if (!$auth_result) { if (Auth::instance()->logged_in()) { //! \todo Flash message. Request::instance()->redirect('user'); } else { Request::instance()->redirect('login'); } } // Try to pre-fetch the template. Doesn't have to succeed. try { $this->template->content = View::factory(Request::instance()->controller . '/' . Request::instance()->action); } catch (Kohana_View_Exception $e) { } $this->template->title = ucwords(Request::instance()->action); $this->template->left = null; $this->template->right = null; $this->template->footer = null; $this->template->no_back_button = true; $this->template->menu = array(); }
public function action_add_to_role($role_id) { $data = array(); $this->template->title = 'Add Controller in Role'; $role = $data['role'] = new Model_Role($role_id); if ($_POST) { //print_r($_POST); if (isset($_POST['controller'])) { $controllers = $_POST['controller']; foreach ($controllers as $ctrl => $id) { $c = new Model_SysController($id); if ($c) { $role->add('syscontrollers', $c); } } Request::instance()->redirect('syscontroller/in_role/' . $role->id); } } $controllers = ORM::factory('SysController')->find_all()->as_array(); $added_controllers = $role->syscontrollers->find_all()->as_array(); $diff = array_diff($controllers, $added_controllers); unset($controllers); unset($added_controllers); $data['controllers'] = $diff; $view = View::factory('pages/syscontroller/add_to_role', $data); $this->template->content = $view->render(); }
/** * 单例 */ public static function getInstance() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
/** * @return Request */ public static function getInstance() { if (!self::$instance instanceof Request) { self::$instance = new Request(); } return self::$instance; }
public function action_signout() { #Sign out the user Auth::instance()->logout(); #redirect to the user account and then the signin page if logout worked as expected Request::instance()->redirect('/admin/site/index'); }
/** * Load pages from database, static view files, * or display 404 error page. */ public function action_load() { Kohana::$log->add(Kohana::DEBUG, 'Executing Controller_Cms_Page::action_load'); $page = Request::instance()->param('page'); $page = Security::xss_clean($page); // Check if page is in cache if (Kohana::$caching === TRUE and $file = Kohana::cache('page_' . $page)) { $this->template->content = $file; return; } // Default values $contents = NULL; $found = FALSE; // Check if page is in database $db = DB::select('title', 'text')->from('pages')->where('slug', '=', $page)->execute(); if ($db->count() == 1) { $contents = $db->current(); $contents = $contents['text']; $found = TRUE; } else { if (Kohana::find_file('views', 'static/' . $page)) { $contents = new View('static/' . $page); $found = TRUE; } else { Kohana::$log->add(Kohana::ERROR, 'Page controller error loading non-existent page, ' . $page); $contents = new View('errors/404'); } } if (Kohana::$caching === TRUE and $found) { Kohana::cache('page_' . $page, $contents); } $this->template->content = $contents; }