/** * Returns if the client has access to this form. * * @return boolean */ public function authorize() { // Ban check. $ban = Ban::getBan($this->ip(), $this->board->board_uri); if ($ban) { $this->ban = $ban; return false; } // Locked thread check. if ($this->thread instanceof Post && $this->thread->isLocked() && !$this->user->canPostInLockedThreads($this->board)) { return false; } ## TODO ## // Separate these permsisions. return $this->user->canPostThread() || $this->user->canPostReply(); }
/** * Converts a single post in standard legacy API output. * * @param \App\Post $post * @return array */ protected function postToJson(Post $post) { // Actual post information. $postArray = ['no' => (int) $post->board_id, 'resto' => (int) $post->reply_to_board_id ?: 0, 'sticky' => (bool) $post->isStickied(), 'locked' => (bool) $post->isLocked(), 'cyclical' => (bool) $post->isCyclic(), 'name' => (string) $post->author, 'sub' => (string) $post->subject, 'com' => (string) $post->getBodyFormatted(), 'time' => (int) $post->created_at->timestamp, 'last_modified' => (int) $post->bumped_last->timestamp, 'omitted_posts' => 0, 'omitted_images' => 0]; // Attachment information. foreach ($post->attachments as $attachmentIndex => $attachment) { $attachmentArray = ['filename' => $attachment->getBaseFileName(), 'ext' => "." . $attachment->getExtension(), 'tim' => $attachment->getFileName("%t-%i"), 'md5' => base64_encode(hex2bin($attachment->hash)), 'fsize' => $attachment->filesize, 'tn_h' => $attachment->thumbnail_height, 'tn_w' => $attachment->thumbnail_width, 'h' => $attachment->file_height, 'w' => $attachment->file_width]; if ($attachmentIndex === 0) { $postArray = array_merge($postArray, $attachmentArray); } else { if (!isset($postArray['extra_files'])) { $postArray['extra_files'] = []; } $postArray['extra_files'][] = $attachmentArray; } } return $postArray; }