3 namespace Friendica\Module;
5 use Friendica\BaseModule;
7 use Friendica\Model\Item;
10 * Toggle starred items
12 class Starred extends BaseModule
14 public static function rawContent(array $parameters = [])
17 throw new \Friendica\Network\HTTPException\ForbiddenException();
20 if (empty($parameters['item'])) {
21 throw new \Friendica\Network\HTTPException\BadRequestException();
24 $itemId = intval($parameters['item']);
26 $item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]);
28 throw new \Friendica\Network\HTTPException\NotFoundException();
31 $starred = !(bool)$item['starred'];
33 Item::update(['starred' => $starred], ['id' => $itemId]);
35 // See if we've been passed a return path to redirect to
36 $returnPath = $_REQUEST['return'] ?? '';
37 if (!empty($returnPath)) {
38 $rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand';
39 DI::app()->internalRedirect($returnPath . $rand);
42 // the json doesn't really matter, it will either be 0 or 1
43 echo json_encode((int)$starred);