public function handle() { $this->page = Page::find_by_title($this->request->page); # Action tree if ($this->request->action_is('save')) { # TODO: validate request before saving if (strlen($this->request->post('wmd-input')) > self::MAX_BODY_LENGTH) { $this->t->flash('Page content is too long. Please shorten.', 'warning'); $this->t->data('page-body', $this->request->post('wmd-input')); } else { $this->page->set('body', $this->request->post('wmd-input')); $this->page->save(); NeechyResponse::redirect($this->page->url()); } } elseif ($this->request->action_is('preview')) { $markdown = new Parsedown(); $preview_html = $markdown->text($this->request->post('wmd-input')); $this->t->data('preview', $preview_html); $this->t->data('page-body', $this->request->post('wmd-input')); } elseif ($this->request->action_is('edit')) { $this->t->data('page-body', $this->request->post('wmd-input')); } else { $this->t->data('page-body', $this->page->field('body')); } # Partial variables $last_edited = sprintf('Last edited by %s on %s', $this->page->editor_link(), $this->page->field('created_at')); $page_title = NeechyTemplater::titleize_camel_case($this->page->get_title()); # Render partial $this->t->data('action', $this->request->action); $this->t->data('page-title', $page_title); $this->t->data('last-edited', $last_edited); $content = $this->render_view('editor'); # Return response return $this->respond($content); }
public function handle() { $this->page = Page::find_by_title($this->request->page); # Partial variables $last_edited = sprintf('Last edited by %s on %s', $this->page->editor_link(), $this->page->field('created_at')); $page_title = NeechyTemplater::titleize_camel_case($this->page->get_title()); # Render partial $this->t->data('page-title', $page_title); $this->t->data('panel-content', $this->page->body_to_html()); $this->t->data('last-edited', $last_edited); # Return response if ($this->request->format == 'ajax') { return new NeechyResponse($this->page->to_json(), 200); } else { $content = $this->render_view('content'); return $this->respond($content); } }