mirror of
https://github.com/friendica/friendica
synced 2025-04-19 07:10:11 +00:00
Merge remote-tracking branch 'upstream/develop' into post-thread-user
This commit is contained in:
commit
be3dfb4ffe
25 changed files with 20276 additions and 18222 deletions
77
src/Module/Item/Follow.php
Normal file
77
src/Module/Item/Follow.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Item;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* Module for following threads
|
||||
*/
|
||||
class Follow 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']);
|
||||
|
||||
if (!Item::performActivity($itemId, 'follow', local_user())) {
|
||||
throw new HTTPException\BadRequestException($l10n->t('Unable to follow this item.'));
|
||||
}
|
||||
|
||||
// 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' => 'follow',
|
||||
'state' => 1
|
||||
];
|
||||
|
||||
System::jsonExit($return);
|
||||
}
|
||||
}
|
82
src/Module/Item/Star.php
Normal file
82
src/Module/Item/Star.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Item;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
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(), ['starred'], ['uid' => local_user(), 'id' => $itemId]);
|
||||
if (empty($item)) {
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue