示例#1
0
 public function onQuote()
 {
     if (!($user = Auth::getUser())) {
         throw new ApplicationException('You should be logged in.');
     }
     if (!($post = PostModel::find(post('post')))) {
         throw new ApplicationException('Unable to find that post.');
     }
     $result = $post->toArray();
     $result['author'] = $post->member ? $post->member->username : '******';
     return $result;
 }
示例#2
0
 public function onUpdate()
 {
     $this->page['member'] = $member = $this->getMember();
     $topic = $this->getTopic();
     $post = PostModel::find(post('post'));
     if (!$post->canEdit()) {
         throw new ApplicationException('Permission denied.');
     }
     /*
      * Supported modes: edit, view, delete, save
      */
     $mode = post('mode', 'edit');
     if ($mode == 'save') {
         if (!$topic || !$topic->canPost()) {
             throw new ApplicationException('You cannot edit posts or make replies.');
         }
         $post->save(post());
         // First post will update the topic subject
         if ($topic->first_post->id == $post->id) {
             $topic->save(['subject' => post('subject')]);
         }
     } elseif ($mode == 'delete') {
         $post->delete();
     }
     $this->page['mode'] = $mode;
     $this->page['post'] = $post;
     $this->page['topic'] = $topic;
 }