Ejemplo n.º 1
0
 public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $page = new Page();
     $id = $context->get('id');
     $title = $context->get('title');
     $content = $context->get('content');
     $page->setId($id);
     if (isset($title) && isset($content)) {
         $page->setTitle($title);
         $page->setContent($content);
         $mapper->update($page);
     } else {
         $mapper->find($page);
     }
     $title = $page->getTitle();
     if (empty($title)) {
         throw new ResourceNotFoundException('The page could not be found.');
     }
     $variables = (array) $page;
     $variables['action'] = url('page', $id, 'edit');
     $template = new Template('Nigel:WebsitePackage:html', array('title' => "Editing page <em>{$page->getTitle()}</em>", 'page' => new Template('Nigel:WebsitePackage:page:edit', $variables)));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript(array('Nigel:WebsitePackage:default', 'Nigel:WebsitePackage:jquery', 'Nigel:WebsitePackage:ckeditor:ckeditor', 'Nigel:WebsitePackage:editor'));
     return new Response($template->render());
 }
Ejemplo n.º 2
0
 public function execute(Context $context)
 {
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Welcome', 'page' => '<p>No homepage has been set.</p>'));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return new Response($template->render());
 }
Ejemplo n.º 3
0
 public function execute(Context $context)
 {
     $session = new Session();
     $response = new Response();
     $session->start();
     if ($session->valid()) {
         return $response->redirect(url());
     }
     $username = $context->get('username');
     $password = $context->get('password');
     if (isset($username) && isset($password)) {
         $mapper = new UserMapper();
         $user = new User();
         $user->setUsername($username);
         $mapper->find($user);
         if (hash('sha256', $password) == $user->getPassword()) {
             $session->validate($context);
             return $response->redirect(url());
         }
         throw new AccessDeniedException('Incorrect username or password');
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Login', 'page' => new Template('Nigel:WebsitePackage:login:login', array('action' => url('login')))));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return $response->content($template->render());
 }
 public function execute(Context $context)
 {
     $code = $context->get('code');
     $uri = $context->get('uri');
     $message = $context->get('message');
     $level = $code < 500 ? 'warning' : 'error';
     $protocol = $context->get('SERVER_PROTOCOL');
     switch ($code) {
         case HttpError::ACCESS_DENIED:
             $title = '403: Forbidden';
             $realMessage = "Access denied. {$message}";
             $status = "{$protocol} 403 Forbidden";
             break;
         case HttpError::NOT_FOUND:
             $title = '404: Not Found';
             $realMessage = "The page {$uri} could not be found.";
             $status = "{$protocol} 404 Not Found";
             break;
         default:
             $title = '500: Internal Server Error';
             $realMessage = "The server encountered an error: {$message}";
             $status = "{$protocol} 500 Internal Server Error";
     }
     $httpError = new HttpError(array('title' => $title, 'code' => $code, 'uri' => $uri, 'message' => $realMessage, 'level' => $level));
     $template = new Template('::base', array('title' => $httpError->getTitle(), 'content' => new Template('::HttpError:View', (array) $httpError), 'level' => $httpError->getLevel()));
     $template->addStyle('::normalize')->addStyle('::layout')->addStyle('::typography')->addStyle('::color');
     $response = new Response($template->render());
     return $response->status($status);
 }
Ejemplo n.º 5
0
 public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $page = new Page();
     $response = new Response();
     $title = $context->get('title');
     $content = $context->get('content');
     if (isset($title) && isset($content)) {
         $page->setTitle($title);
         $page->setContent($content);
         $mapper->create($page);
         return $response->redirect(url('page', $page->getId()));
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => 'Create new page', 'page' => new Template('Nigel:WebsitePackage:page:edit', array('title' => '', 'content' => '', 'action' => url('page', 'create')))));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript(array('Nigel:WebsitePackage:default', 'Nigel:WebsitePackage:jquery', 'Nigel:WebsitePackage:ckeditor:ckeditor', 'Nigel:WebsitePackage:editor'));
     return $response->content($template->render());
 }
Ejemplo n.º 6
0
 public function execute(Context $context)
 {
     $mapper = new PageMapper();
     $id = $context->get('id');
     if ($id == 'all') {
         $pages = $mapper->findAll();
         $title = 'All Content';
         $content = new Template('Nigel:WebsitePackage:page:index', array('pages' => $pages));
     } else {
         $page = new Page();
         $page->setId($id);
         $mapper->find($page);
         $title = $page->getTitle();
         $content = new Template('Nigel:WebsitePackage:page:view', (array) $page);
     }
     $template = new Template('Nigel:WebsitePackage:html', array('title' => $title, 'page' => $content));
     $template->addStyle('Nigel:WebsitePackage:default');
     $template->addScript('Nigel:WebsitePackage:default');
     return new Response($template->render());
 }