Example #1
0
 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);
 }
Example #2
0
 private function save_user_page($user)
 {
     $path = NeechyPath::join($this->html_path(), 'new-page.md.php');
     $page = Page::find_by_title($user->field('name'));
     $page->set('body', $this->t->render_partial_by_path($path));
     $page->set('editor', 'NeechySystem');
     $page->save();
     return $page;
 }
 /**
  * Tests
  */
 public function testShouldDisplayAuthView()
 {
     $request = new NeechyRequest();
     $page = Page::find_by_title('logout');
     $handler = new AuthHandler($request, $page);
     $response = $handler->handle();
     $this->assertEquals(200, $response->status);
     $this->assertContains(sprintf('<button class="%s" type="submit">Sign in</button>', 'btn btn-lg btn-primary btn-block'), $response->body);
     $this->assertContains(sprintf('<button class="%s" type="submit">Sign up</button>', 'btn btn-lg btn-primary btn-block'), $response->body);
 }
 /**
  * Tests
  */
 public function testShouldDisplayPage()
 {
     $request = new NeechyRequest();
     $page = Page::find_by_title('NeechyPage');
     $handler = new PageHandler($request, $page);
     $response = $handler->handle();
     $this->assertEquals(200, $response->status);
     $this->assertContains('<div class="tab-pane page active" id="read">', $response->body);
     # TODO: Figure out why this doesn't pass as expected.
     #$this->assertContains($page->body_to_html(), $response->body);
 }
Example #5
0
 public function handle()
 {
     $this->page = Page::find_by_title($this->request->page);
     $edits = $this->page->load_history();
     if ($this->request->format == 'ajax') {
         return new NeechyResponse(json_encode($edits), 200);
     } else {
         $this->t->data('edits', $edits);
         $content = $this->render_view('table');
         return $this->respond($content);
     }
 }
Example #6
0
 public function testFindByTitle()
 {
     $page = Page::find_by_title('NewPage');
     # page does not exist yet
     $this->assertEquals('NewPage', $page->field('title'));
     $this->assertTrue($page->is_new());
     $page = Page::find_by_title('NeechyPage');
     $this->assertEquals('NeechyPage', $page->field('title'));
     $this->assertEquals('version 3', $page->field('note'));
     $this->assertEquals('version 1', $page->primogenitor->field('note'));
     $this->assertFalse($page->is_new());
 }
 public function testShouldRedisplayEditorWhenEditButtonPushed()
 {
     $page = Page::find_by_title('NeechyPage');
     # Edit action requires hidden textarea.
     $_POST['action'] = 'edit';
     $_POST['wmd-input'] = $page->field('body');
     # POST vars must be set before NeechyRequest called.
     $request = new NeechyRequest();
     $handler = new EditorHandler($request, $page);
     $response = $handler->handle();
     $this->assertEquals(200, $response->status);
     $this->assertContains('<div id="wmd-editor" class="wmd-panel">', $response->body);
     $this->assertContains($page->field('body'), $response->body);
 }
 /**
  * Tests
  */
 public function testShouldDisplay404Error()
 {
     $request = new NeechyRequest();
     $page = Page::find_by_title('NeechyPage');
     try {
         throw new NeechyWebServiceError('Testing 404 Error', 404);
     } catch (NeechyError $e) {
         $handler = new ErrorHandler($request);
         $response = $handler->handle_error($e);
     }
     $this->assertEquals(404, $response->status);
     $this->assertContains($e->getMessage(), $response->body);
     $this->assertContains('Testing 404 Error', $response->body);
 }
Example #9
0
 public static function create_on_install()
 {
     $pages_created = array();
     $pages_dir = NeechyPath::join(NEECHY_APP_PATH, 'templates/core_pages');
     $templater = NeechyTemplater::load();
     foreach (self::$core_pages as $name) {
         $basename = sprintf('%s.md.php', $name);
         $path = NeechyPath::join($pages_dir, $basename);
         $page_body = $templater->render_partial_by_path($path);
         $page = Page::find_by_title($name);
         $page->set('body', $page_body);
         $page->set('editor', NEECHY_USER);
         $page->save();
         $pages_created[] = $page;
     }
     return $pages_created;
 }
Example #10
0
 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);
     }
 }
Example #11
0
 public function validate_signup_user($value, $error_key = 'base')
 {
     if ($this->string_is_empty($value)) {
         $message = 'User name required';
         $this->add_error($error_key, $message);
         return FALSE;
     }
     if ($this->string_is_too_short($value, self::MIN_USERNAME_LENGTH)) {
         $message = sprintf('User name too short: must be at least %d chars', self::MIN_USERNAME_LENGTH);
         $this->add_error($error_key, $message);
         return FALSE;
     }
     if (!preg_match(self::RE_VALID_USERNAME, $value)) {
         $message = 'Invalid format: please use something like neechy, ' . 'neechy_user, or NeechyUser';
         $this->add_error($error_key, $message);
         return FALSE;
     }
     # Name used by another user/page
     $user = User::find_by_name($value);
     if ($user->exists()) {
         $message = 'This user name is not available. Please choose another.';
         $this->add_error($error_key, $message);
         return FALSE;
     }
     $page = Page::find_by_title($value);
     if (!$page->is_new()) {
         $message = 'This user name is not available. Please choose another.';
         $this->add_error($error_key, $message);
         return FALSE;
     }
     return TRUE;
 }
Example #12
0
 protected function register_admin_user($name, $email, $password)
 {
     $level = 'ADMIN';
     # Create user and default page
     $user = User::register($name, $email, $password, $level);
     # Create default page
     $path = NeechyPath::join($this->html_path(), 'owner-page.md.php');
     $page = Page::find_by_title($user->field('name'));
     $page->set('body', $this->read_page_body_from_template($path));
     $page->set('editor', 'NeechySystem');
     $page->save();
     return $page;
 }