2019-11-09 04:17:18 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module;
|
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2019-11-09 04:17:18 +01:00
|
|
|
use Friendica\Model\Item;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle pinned items
|
|
|
|
*/
|
|
|
|
class Pinned extends BaseModule
|
|
|
|
{
|
|
|
|
public static function rawContent(array $parameters = [])
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
|
|
|
throw new \Friendica\Network\HTTPException\ForbiddenException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($parameters['item'])) {
|
|
|
|
throw new \Friendica\Network\HTTPException\BadRequestException();
|
|
|
|
}
|
|
|
|
|
|
|
|
$itemId = intval($parameters['item']);
|
|
|
|
|
|
|
|
$pinned = !Item::getPinned($itemId, local_user());
|
|
|
|
|
|
|
|
Item::setPinned($itemId, local_user(), $pinned);
|
|
|
|
|
|
|
|
// See if we've been passed a return path to redirect to
|
|
|
|
$returnPath = $_REQUEST['return'] ?? '';
|
|
|
|
if (!empty($returnPath)) {
|
|
|
|
$rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand';
|
2019-12-16 00:28:31 +01:00
|
|
|
DI::baseUrl()->redirect($returnPath . $rand);
|
2019-11-09 04:17:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// the json doesn't really matter, it will either be 0 or 1
|
|
|
|
echo json_encode((int)$pinned);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|