예제 #1
0
파일: Thread.php 프로젝트: bstats/b-stats
 /**
  * addPost
  *
  * @param Post $post post to be added to the thread's array of posts.
  */
 function addPost($post)
 {
     $post->setBoard($this->board);
     $post->setThread($this);
     $this->posts[] = $post;
     $this->postIds[] = $post->getNo();
     $this->parseQuotes($post->com, $post->no);
 }
예제 #2
0
파일: Yotsuba.php 프로젝트: bstats/b-stats
 /**
  * Formats a plain-text post with HTML.
  *
  * Notes:
  * - cross-board or cross-thread links are not fixed, but instead left as
  *   deadlinks.
  * - <code>&lt;wbr&gt;</code> tags are not replaced.
  *
  * @param Post $post
  * @return string HTML-formatted comment
  */
 public static function toHtml(Post $post)
 {
     $comment = $post->getComment();
     $posts = $post->hasThread() ? $post->getThread()->getPostIds() : [];
     $search[0] = '~&gt;&gt;([0-9]{1,9})~';
     // >>123 type post links
     $search[1] = "~^&gt;(.*)\$~m";
     // >greentext
     $search[2] = "~&gt;&gt;&gt;/([a-z]{1,4})/~";
     // >>>/board/ links
     $search[3] = "~&gt;&gt;&gt;/([a-z]{1,4})/([0-9]{1,9})~";
     // >>>/board/123 type post links
     $replace[0] = '<a href="" class="quotelink">&gt;&gt;$1</a>';
     $replace[1] = '<span class="quote">&gt;$1</span>';
     $replace[2] = '<a href="/$1/" class="quotelink">&gt;&gt;&gt;/$1/</a>';
     $replace[3] = '<span class="deadlink">&gt;&gt;&gt;/$1/$2</span>';
     $srch = array('&', "'", '<', '>', '"');
     $rpl = array("&amp;", '&#039;', '&lt;', '&gt;', "&quot;");
     $htmlSpecialCharComment = str_replace($srch, $rpl, $comment);
     $initialTagComment = preg_replace($search, $replace, $htmlSpecialCharComment);
     $formattedComment = preg_replace_callback('~<a href="" class="quotelink">&gt;&gt;([0-9]{1,9})</a>~', function ($matches) use($posts, $post) {
         if (in_array($matches[1], $posts)) {
             return '<a href="#p' . $matches[1] . '" class="quotelink" ' . 'data-board="' . $post->getBoard()->getName() . '"' . 'data-thread="' . $post->getThreadId() . '"' . 'data-post="' . $matches[1] . '"' . '>&gt;&gt;' . $matches[1] . '</a>';
         } else {
             try {
                 $threadId = Model::get()->getThreadId($post->getBoard(), $matches[1]);
                 return '<a href="' . $threadId . '#p' . $matches[1] . '" class="quotelink" ' . 'data-board="' . $post->getBoard()->getName() . '"' . 'data-thread="' . $threadId . '"' . 'data-post="' . $matches[1] . '"' . '>&gt;&gt;' . $matches[1] . '</a>';
             } catch (\NotFoundException $ex) {
                 return '<span class="deadlink">&gt;&gt;' . $matches[1] . '</span>';
             }
         }
     }, $initialTagComment);
     $formattedComment = str_replace("\r", "", $formattedComment);
     $finalComment = str_replace("\n", "<br>", $formattedComment);
     return $finalComment;
 }
예제 #3
0
 private static function fuukaFormat(Post $post) : array
 {
     $fuukaData = ['doc_id' => $post->getDocId(), 'num' => $post->getNo(), 'subnum' => 0, 'thread_num' => $post->getThreadId(), 'op' => $post->getNo() == $post->getThreadId() ? 1 : 0, 'fourchan_date' => $post->getChanTime(), 'timestamp' => $post->getTime(), 'name' => $post->name, 'name_processed' => $post->getName(), 'email' => $post->email, 'email_processed' => $post->getEmail(), 'trip' => $post->trip, 'trip_processed' => $post->getTripcode(), 'poster_hash_processed' => $post->getID(), 'poster_hash' => $post->id, 'comment_sanitized' => Yotsuba::toBBCode($post->getComment()), 'comment' => Yotsuba::toBBCode($post->getComment()), 'comment_processed' => $post->getComment(), 'title' => $post->sub, 'title_processed' => $post->getSubject()];
     if ($post->hasImage()) {
         $fuukaData['media'] = ['op' => $post->getThreadId() == $post->getNo() ? 1 : 0, 'preview_w' => $post->getThumbWidth(), 'preview_h' => $post->getThumbHeight(), 'media_filename' => $post->getFullFilename(), 'media_filename_processed' => $post->getFullFilename(), 'media_w' => $post->getWidth(), 'media_h' => $post->getHeight(), 'media_size' => $post->getFilesize(), 'media_hash' => base64_encode($post->getMD5Bin()), 'media_orig' => $post->getTim() . $post->getExtension(), 'media' => $post->getTim() . $post->getExtension(), 'preview_reply' => $post->getTim() . "s.jpg", 'remote_media_link' => $post->getImgUrl(), 'media_link' => $post->getImgUrl(), 'thumb_link' => $post->getThumbUrl()];
     } else {
         $fuukaData['media'] = null;
     }
     return $fuukaData;
 }
예제 #4
0
 public static function fixHTML(Post $p) : string
 {
     if ($p->getBoard()->isArchive()) {
         return self::transform4chanHtml($p->getComment(), $p->getBoard(), $p->getThreadId());
     } else {
         return self::transformHtml($p);
     }
 }