main = $main; } /** * handle get call * * @param string|null $_user user to fetch outbox for * @return string|false response */ public function get($_user) { if (!isset($_user)) { return false; } $dbh = $this->main->getDatabase(); $cache = $this->main->getCache(); $connector = $this->main->getConnector(); // get user $user = \Federator\DIO\User::getUserByName( $dbh, $_user, $connector, $cache ); if ($user->id === null) { return false; } // get posts from user $outbox = new \Federator\Data\ActivityPub\Common\Outbox(); $min = $this->main->extractFromURI("min", ""); $max = $this->main->extractFromURI("max", ""); $page = $this->main->extractFromURI("page", ""); if ($page !== "") { $items = \Federator\DIO\Posts::getPostsByUser($dbh, $user->id, $connector, $cache, $min, $max); $outbox->setItems($items); } else { $items = []; } $config = $this->main->getConfig(); $domain = $config['generic']['externaldomain']; $id = 'https://' . $domain . '/users/' . $_user . '/outbox'; $outbox->setPartOf($id); $outbox->setID($id); if ($page !== '') { $id .= '?page=' . urlencode($page); } else { $outbox->setType('OrderedCollection'); } if ($page === '' || $outbox->count() == 0) { $outbox->setFirst($id . '?page=0'); $outbox->setLast($id . '&min=0'); } if (sizeof($items) > 0) { $newestId = $items[0]->getPublished(); $oldestId = $items[sizeof($items) - 1]->getPublished(); $outbox->setNext($id . '&max=' . $newestId); $outbox->setPrev($id . '&min=' . $oldestId); } $obj = $outbox->toObject(); return json_encode($obj, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); } /** * handle post call * * @param string|null $_user user to add data to outbox @unused-param * @return string|false response */ public function post($_user) { return false; } }