public function __construct(Board $board) { parent::__construct("/{$board->getName()}/ - {$board->getLongName()}", "", $board->getPrivilege()); $boardBanner = div("", "boardBanner centertext")->append(div("/{$board->getName()}/ - {$board->getLongName()}", "boardTitle")); if ($board->isArchive()) { $boardBanner->append(a("View this board on 4chan", '//boards.4chan.org/' . $board->getName())); } $this->appendToBody("<hr>" . $boardBanner . "<hr>"); $this->board = $board; }
/** * <code>Thread::parseQuotes</code> searches for inter-post links and adds backlinks to the respective posts. * * @todo Use getters and setters rather than public attributes. * @todo Put this functionality into the b-stats native extension to save server resources. * @todo Better inline comments in this function. * @todo Show if backlinks are from (Dead) posts * @param string $com the post text to be searched * @param string|int $no the id of the post to be searched */ function parseQuotes($com, $no) { $matches = array(); if ($this->board->isArchive()) { $search = '~link">>>(\\d+)</~'; } else { $search = '~>>(\\d+)~'; } preg_match_all($search, $com, $matches); for ($i = 0; $i < count($matches[1]); $i++) { $postno = $matches[1][$i]; for ($j = 0; $j < count($this->posts); $j++) { $p = $this->posts[$j]; if ($p->no == $postno) { if (!in_array($no, $p->backlinks)) { $this->posts[$j]->backlinks[] = $no; } break; } } } }
/** * @param Board $board * @param int $resto * @param $name * @param $trip * @param $email * @param $sub * @param $com * @return Post * @throws NotFoundException */ function addPost(Board $board, int $resto, $name, $trip, $email, $sub, $com, $fileInfo = null) : Post { if ($board->isArchive()) { return null; } if ($resto != 0) { $thread = self::getThread($board, $resto); if ($thread->isClosed()) { throw new Exception("Thread {$resto} is closed; cannot add posts to closed threads."); } } $time = time(); $tim = (int) (microtime(true) * 1000); $stmt = $this->conn_rw->prepare("INSERT INTO `{$board->getName()}_post` " . "(no, resto, time, name, trip, email, sub, com) VALUES (0, :resto, :time, :name, :trip, :email, :sub, :com)"); $stmt->execute([':resto' => $resto, ':time' => $time, ':name' => $name, ':trip' => $trip, ':email' => $email, ':sub' => $sub, ':com' => $com]); $postId = $this->conn_rw->lastInsertId(); $clause = $resto == 0 ? ", `resto`=`doc_id`" : ""; $this->conn_rw->exec("UPDATE `{$board->getName()}_post` SET `no`=`doc_id` {$clause} WHERE `doc_id`={$postId}"); if ($resto == 0) { $this->conn_rw->exec("INSERT INTO `{$board->getName()}_thread` (threadid, active, sticky, closed, archived, custom_spoiler, replies, images, last_crawl, lastreply) " . " VALUES ({$postId}, 1, 0, 0, 0, 0, 0, 0, {$time}, {$time})"); } else { $this->conn_rw->exec("UPDATE `{$board->getName()}_thread` SET `replies`=`replies`+1, `last_crawl`='{$time}', `lastreply`='{$time}' WHERE `threadid`='{$resto}'"); } $this->conn_rw->exec("UPDATE `boards` SET `last_crawl`='{$time}' WHERE `boards`.`shortname` = '{$board->getName()}'"); if ($fileInfo != null) { $this->addFileInfo($board, $postId, $tim, $fileInfo); } return $this->getPost($board, $postId); }