public function action_index() { $twig = Twig::factory('Public/login'); if (Auth::instance()->logged_in()) { HTTP::redirect('admin/games'); } if ($this->request->method() == 'POST') { $post = $this->request->post(); $twig->post = $post; $success = Auth::instance()->login($post['username'], $post['password']); if ($success) { $user = Auth::instance()->get_user(); if ($user->state == 2) { Auth::instance()->logout(); $error = 'Your account has been locked. Please contact an administrator.'; } else { $login = ORM::factory('Login'); $login->user_id = $user->id; $login->ip_address = Request::$client_ip; $login->login_date = date('Y-m-d H:i:s'); $login->save(); Session::instance()->set('userData', $login->as_array()); HTTP::redirect('admin/games'); } } else { $error = 'The user name or password is incorrect.'; } $twig->error = $error; } $this->response->body($twig); }
public function get_response() { $twig = Twig::factory('frontend/main'); $response = $twig->render('Public/404'); $response = Response::factory()->status(404)->body($response); return $response; }
public function action_index() { $twig = Twig::factory('Public/register'); if (Auth::instance()->logged_in()) { HTTP::redirect('admin/dashboard'); } $settings = ORM::factory('Setting')->where('id', '=', 1)->where('registration_status', '=', 1)->find(); if ($settings->loaded()) { $registration = true; $twig->registrationStatus = null; } else { $registration = false; $twig->registrationStatus = 'Registration is currently off.'; } if ($this->request->method() == 'POST') { $post = $this->request->post(); $twig->post = $post; $errorMessages = array(); $controllerValidation = Validation::factory($post)->rule('terms', 'not_empty')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', 4))->rule('password', 'max_length', array(':value', 30)); if ($registration) { if ($controllerValidation->check()) { try { $register = ORM::factory('User'); $register->username = $post['username']; $register->email = $post['email']; $register->password = $post['password']; $register->save(); $adminRole = ORM::factory('Role', 1); $register->add('roles', $adminRole); $twig->success = 'You have successfully registered.'; $twig->post = null; } catch (ORM_Validation_Exception $e) { $errorMessages = $e->errors('models'); } } else { $errors = $controllerValidation->errors(); foreach ($errors as $key => $value) { if ($key == 'terms' and $value[0] == 'not_empty') { $errorMessages[] = 'Please agree with terms and conditions to register.'; } if ($key == 'password' and $value[0] == 'not_empty') { $errorMessages[] = 'Please enter your password.'; } if ($key == 'password' and $value[0] == 'min_length') { $errorMessages[] = 'Password is too short.'; } if ($key == 'password' and $value[0] == 'max_length') { $errorMessages[] = 'Password is too long.'; } } } } else { $errorMessages[] = 'Registration is currently off.'; } $twig->errors = $errorMessages; } $this->response->body($twig); }
public function action_index() { $twig = Twig::factory('Public/index'); $games = ORM::factory('Game')->where('state', '=', 1)->order_by('name', 'ASC')->find_all(); $data = array('games' => $games); $session = Session::instance(); $session->delete('registrationState', 'registrationUsername', 'registrationClass', 'registrationHero'); $twig->games = $games; $this->response->body($twig); }
public function action_index() { $slug = $this->request->param('slug'); $game = ORM::factory('Game')->where('slug', '=', $slug)->find(); if (!$game->loaded()) { throw new HTTP_Exception_404(); } $twig = Twig::factory('Public/game'); $twig->game = $game; $this->response->body($twig); }
public function testRender() { Kohana::$config->shouldReceive('load')->with('twig')->once()->andReturn(Kohana::$config); Kohana::$config->shouldReceive('get')->with('loader')->once()->andReturn(array('extension' => 'html', 'path' => '')); Kohana::$config->shouldReceive('get')->with('environment')->once()->andReturn(array('auto_reload' => Kohana::$environment == Kohana::DEVELOPMENT, 'autoescape' => TRUE, 'base_template_class' => 'Twig_Template', 'cache' => APPPATH . 'cache/twig', 'charset' => 'utf-8', 'optimizations' => -1, 'strict_variables' => FALSE)); Kohana::$config->shouldReceive('get')->with('functions')->once()->andReturn(array()); Kohana::$config->shouldReceive('get')->with('filters')->once()->andReturn(array()); Kohana::$config->shouldReceive('get')->with('tests')->once()->andReturn(array()); $twig = Twig::factory(); $twig->hello = 'Hello World!'; $view = $twig->render('tests/test'); $this->assertEquals("Hello World!", trim($view)); }
public function action_index() { $twig = Twig::factory('Admin/reports'); $twig->totalGames = ORM::factory('Game')->where('state', '=', 1)->count_all(); $twig->totalCompleted = ORM::factory('Game')->where('state', '=', 1)->where('status', '=', 'Completed')->or_where('status', '=', 'Played')->count_all(); $twig->totalSpent = 0; $twig->editions = ORM::factory('Edition')->where('state', '=', 1)->order_by('edition', 'ASC')->find_all(); $twig->sources = ORM::factory('Source')->where('state', '=', 1)->order_by('source', 'ASC')->find_all(); $twig->genres = ORM::factory('Genre')->where('state', '=', 1)->order_by('genre', 'ASC')->find_all(); $twig->platforms = ORM::factory('Platform')->where('state', '=', 1)->order_by('platform', 'ASC')->find_all(); $twig->developers = ORM::factory('Game')->where('state', '=', 1)->order_by('developer', 'ASC')->group_by('developer')->find_all(); $twig->publishers = ORM::factory('Game')->where('state', '=', 1)->order_by('publisher', 'ASC')->group_by('publisher')->find_all(); $this->response->body($twig); }
public function before() { parent::before(); $controller = $this->request->controller(); $action = $this->request->action(); $this->template = Twig::factory(strtolower($controller . '/' . $action)); if ($this->auto_render === true) { /** @var Twig $engine */ $engine = $this->engine; $engine::set_global('app', array('request' => $this->request, 'host_name' => $_SERVER['HTTP_HOST'])); $engine::bind_global('styles', $this->_styles); $engine::bind_global('scripts', $this->_scripts); } }
public static function factory($controller, $format = null) { if (is_a($controller, 'Controller_Site')) { $format = $controller->request->param('format', 'html'); switch ($format) { case 'html': $template; if (empty($controller->template)) { // Generate a template name if one wasn't set. $template = str_replace('_', '/', $controller->request->controller) . '/' . $controller->request->action; } else { $template = $controller->template; } if ($controller->auto_render) { // Load the twig template. $template = Twig::factory($template, 'default'); // Return the twig environment $controller->environment = $template->environment(); } return $template; break; case 'json': return new Jx_View_Json($controller->request); break; case 'rss': break; case 'xml': break; } } elseif (is_string($controller)) { if (is_null($format)) { $format = 'html'; } switch ($format) { case 'html': $template = $controller; return Twig::factory($template, 'default'); break; case 'json': if (is_a($controller, 'Request')) { return new Jx_View_Json($controller); } else { return new Jx_View_Json(); } break; } } }
/** * Setup view * * @return void */ public function before() { if (empty($this->template)) { // Generate a template name if one wasn't set. $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller) . DIRECTORY_SEPARATOR . $this->request->action; if (!empty($this->request->directory)) { $this->template = $this->request->directory . DIRECTORY_SEPARATOR . $this->template; } } if ($this->auto_render) { // Load the twig template. $this->template = Twig::factory($this->template, $this->environment); // Return the twig environment $this->environment = $this->template->environment(); } return parent::before(); }
public function action_index() { $twig = Twig::factory('Admin/sources'); // Handling POST data from all forms on the page if ($this->request->method() == 'POST') { $post = $this->request->post(); $twig->post = $post; if ($post['type'] == 'addSource') { $query = ORM::factory('Source')->where('source', '=', $post['source'])->where('state', '=', 1)->find(); if ($query->loaded()) { $twig->errorAdd = array('source' => 'Source name is already in use.'); } else { try { $source = ORM::factory('Source'); $user = Auth::instance()->get_user(); $source->source = $post['source']; $source->user_id = $user->id; $source->save(); $twig->post = null; } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); $twig->errorAdd = $errors; } } } if ($post['type'] == 'deleteSource') { if (!isset($post['source'])) { $post['source'] = null; } $source = ORM::factory('Source', $post['source']); if ($source->loaded()) { $user = Auth::instance()->get_user(); $source->state = 2; $source->user_id = $user->id; $source->save(); $twig->post = null; } else { $twig->errorDelete = 'Please select source to delete.'; } } } // Getting data from the database $sources = ORM::factory('Source')->where('state', '=', 1)->order_by('id', 'ASC')->find_all(); $twig->sources = $sources; $this->response->body($twig); }
/** * Setup view * * @return void */ public function __construct(Request $request, Response $response) { parent::__construct($request, $response); if (empty($this->template)) { // Generate a template name if one wasn't set. $this->template = str_replace('_', DIRECTORY_SEPARATOR, $this->request->controller()) . DIRECTORY_SEPARATOR . $this->request->action(); $directory = $this->request->directory(); if (!empty($directory)) { $this->template = $this->request->directory() . DIRECTORY_SEPARATOR . $this->template; } } if ($this->auto_render) { // Load the twig template. $this->template = Twig::factory($this->template, $this->environment); // Return the twig environment $this->environment = $this->template->environment(); } }
public function action_index() { $twig = Twig::factory('Admin/settings'); if ($this->request->method() == 'POST') { $post = $this->request->post(); $twig->post = $post; if ($post['type'] == 'registration') { $setting = ORM::factory('Setting', 1); if ($setting->loaded()) { $user = Auth::instance()->get_user(); $setting->registration_status = $post['registrationStatus']; $setting->user_id = $user->id; $setting->save(); $twig->successRegistration = 'Settings have been saved.'; } } } $twig->settings = ORM::factory('Setting')->where('id', '=', 1)->find(); $this->response->body($twig); }
/** * Renders the template if necessary * * @return void */ public function after() { // Output the template automatically (if applicable) if ((bool) $this->_template_path) { if ((bool) $this->_auto_render) { $this->response->body(Twig::factory($this->_template_path, $this->__context, $this->_environment)->render()); } } }
public function action_index() { $twig = Twig::factory('Admin/games'); $loadedId = $this->request->param('id'); if ($loadedId) { $loadedGame = ORM::factory('Game')->where('id', '=', $loadedId)->find(); if (!$loadedGame->loaded()) { throw new HTTP_Exception_404(); } else { function formatdateOutput($date) { if ($date == '0000-00-00') { $formattedDate = null; } else { $formattedDate = date('m/Y', strtotime(str_replace('/', '-', $date))); } return $formattedDate; } $price = number_format($loadedGame->price, 2); if ($price == 0) { $price = null; } $twig->post = array('name' => $loadedGame->name, 'platform' => $loadedGame->platform, 'genre' => $loadedGame->genre, 'rarity' => $loadedGame->rarity, 'edition' => $loadedGame->edition, 'condition' => $loadedGame->condition, 'status' => $loadedGame->status, 'developer' => $loadedGame->developer, 'publisher' => $loadedGame->publisher, 'release' => formatdateOutput($loadedGame->release), 'source' => $loadedGame->source, 'price' => $price, 'acquired' => formatdateOutput($loadedGame->acquired), 'type' => 'addGame'); } } if ($this->request->method() == 'POST') { $post = $this->request->post(); $twig->post = $post; if ($post['type'] == 'addGame') { if (!isset($post['platform'])) { $platform = null; } else { $platform = $post['platform']; } if (!isset($post['genre'])) { $genre = null; } else { $genre = $post['genre']; } if (!isset($post['edition'])) { $edition = null; } else { $edition = $post['edition']; } if (!isset($post['source'])) { $source = null; } else { $source = $post['source']; } if (!ORM::factory('Platform')->where('id', '=', $platform)->where('state', '=', 1)->find()->loaded()) { $twig->errorAdd = array('game' => 'Platform does not exist.'); } else { if (!ORM::factory('Genre')->where('id', '=', $genre)->where('state', '=', 1)->find()->loaded()) { $twig->errorAdd = array('game' => 'Genre does not exist.'); } else { if (!ORM::factory('Edition')->where('id', '=', $edition)->where('state', '=', 1)->find()->loaded()) { $twig->errorAdd = array('game' => 'Edition does not exist.'); } else { if (!ORM::factory('Source')->where('id', '=', $source)->where('state', '=', 1)->find()->loaded()) { $twig->errorAdd = array('game' => 'Source does not exist.'); } else { try { function formatdateDatabase($date) { if ($date) { $formattedDate = date('Y-m-d H:i:s', strtotime(str_replace('/', '-', '01/' . $date))); } else { $formattedDate = null; } return $formattedDate; } $game = ORM::factory('Game', $loadedId); $user = Auth::instance()->get_user(); $game->user_id = $user->id; $game->name = $post['name']; $game->platform = $platform; $game->genre = $genre; $game->rarity = $post['rarity']; $game->edition = $edition; $game->condition = $post['condition']; $game->status = $post['status']; $game->developer = $post['developer']; $game->publisher = $post['publisher']; $game->source = $source; $game->price = $post['price']; $game->release = formatdateDatabase($post['release']); $game->acquired = formatdateDatabase($post['acquired']); $game->save(); if (!$loadedId) { $twig->post = null; } $twig->successAdd = 'Game has been saved.'; } catch (ORM_Validation_Exception $e) { $errors = $e->errors('models'); $twig->errorAdd = $errors; } } } } } } if ($post['type'] == 'deleteGame') { if (!isset($post['game'])) { $post['game'] = null; } $game = ORM::factory('Game', $post['game']); if ($game->loaded()) { $user = Auth::instance()->get_user(); $game->state = 2; $game->user_id = $user->id; $game->save(); $twig->successDelete = 'Game has been deleted.'; } else { $twig->errorDelete = 'Please select game to delete.'; } } } // Getting data from the database $platforms = ORM::factory('Platform')->where('state', '=', 1)->order_by('platform', 'ASC')->find_all(); $genres = ORM::factory('Genre')->where('state', '=', 1)->order_by('genre', 'ASC')->find_all(); $sources = ORM::factory('Source')->where('state', '=', 1)->order_by('id', 'ASC')->find_all(); $editions = ORM::factory('Edition')->where('state', '=', 1)->order_by('id', 'ASC')->find_all(); $games = ORM::factory('Game')->where('state', '=', 1)->order_by('name', 'ASC')->find_all(); $twig->editions = $editions; $twig->sources = $sources; $twig->platforms = $platforms; $twig->genres = $genres; $twig->games = $games; $this->response->body($twig); }