2021-11-24 18:03:34 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
|
|
|
*
|
|
|
|
* @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\Api\Twitter;
|
|
|
|
|
|
|
|
use Friendica\Core\Logger;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Contact;
|
|
|
|
use Friendica\Model\Post;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the most recent mentions.
|
|
|
|
*
|
|
|
|
* @see http://developer.twitter.com/doc/get/statuses/mentions
|
|
|
|
*/
|
|
|
|
class Favorites extends BaseApi
|
|
|
|
{
|
2021-11-27 13:58:24 -05:00
|
|
|
protected function rawContent(array $request = [])
|
2021-11-24 18:03:34 -05:00
|
|
|
{
|
|
|
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
|
|
|
$uid = BaseApi::getCurrentUserID();
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
// in friendica starred item are private
|
|
|
|
// return favorites only for self
|
2021-11-26 02:55:02 -05:00
|
|
|
Logger::info(BaseApi::LOG_PREFIX . 'for {self}', ['module' => 'api', 'action' => 'favorites']);
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
// params
|
|
|
|
$since_id = $_REQUEST['since_id'] ?? 0;
|
2021-11-24 18:28:06 -05:00
|
|
|
$max_id = $_REQUEST['max_id'] ?? 0;
|
|
|
|
$count = $_GET['count'] ?? 20;
|
|
|
|
$page = $_REQUEST['page'] ?? 1;
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$start = max(0, ($page - 1) * $count);
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `starred`",
|
|
|
|
$uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
if ($max_id > 0) {
|
|
|
|
$condition[0] .= " AND `id` <= ?";
|
|
|
|
$condition[] = $max_id;
|
|
|
|
}
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$statuses = Post::selectForUser($uid, [], $condition, $params);
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-24 18:03:34 -05:00
|
|
|
$ret = [];
|
|
|
|
while ($status = DBA::fetch($statuses)) {
|
|
|
|
$ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
|
|
|
|
}
|
|
|
|
DBA::close($statuses);
|
2021-11-24 18:20:42 -05:00
|
|
|
|
2021-11-28 09:05:42 -05:00
|
|
|
$this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
|
2021-11-24 18:03:34 -05:00
|
|
|
}
|
|
|
|
}
|