. * */ namespace Friendica\Module\Item; use Friendica\BaseModule; use Friendica\Core\Logger; use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Network\HTTPException; /** * Toggle starred items */ class Star extends BaseModule { public static function rawContent(array $parameters = []) { $l10n = DI::l10n(); if (!Session::isAuthenticated()) { throw new HttpException\ForbiddenException($l10n->t('Access denied.')); } if (empty($parameters['id'])) { throw new HTTPException\BadRequestException(); } $itemId = intval($parameters['id']); $item = Post::selectFirstForUser(local_user(), ['uid', 'uri-id', 'starred'], ['uid' => [0, local_user()], 'id' => $itemId]); if (empty($item)) { throw new HTTPException\NotFoundException(); } if ($item['uid'] == 0) { $stored = Item::storeForUserByUriId($item['uri-id'], local_user()); if (!empty($stored)) { $item = Post::selectFirst(['starred'], ['id' => $stored]); if (!DBA::isResult($item)) { throw new HTTPException\NotFoundException(); } $itemId = $stored; } else { throw new HTTPException\NotFoundException(); } } $starred = !(bool)$item['starred']; Item::update(['starred' => $starred], ['id' => $itemId]); // See if we've been passed a return path to redirect to $return_path = $_REQUEST['return'] ?? ''; if (!empty($return_path)) { $rand = '_=' . time(); if (strpos($return_path, '?')) { $rand = "&$rand"; } else { $rand = "?$rand"; } DI::baseUrl()->redirect($return_path . $rand); } $return = [ 'status' => 'ok', 'item_id' => $itemId, 'verb' => 'star', 'state' => (int)$starred, ]; System::jsonExit($return); } }