3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Friendica\Photoalbum;
25 use Friendica\Core\L10n;
26 use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Photo;
29 use Friendica\Module\Api\ApiResponse;
30 use Friendica\Module\BaseApi;
31 use Friendica\Network\HTTPException;
32 use Friendica\Util\Profiler;
33 use Psr\Log\LoggerInterface;
36 * api/friendica/photoalbum/:name
38 * @package Friendica\Module\Api\Friendica\Photoalbum
40 class Show extends BaseApi
42 /** @var FriendicaPhoto */
43 private $friendicaPhoto;
46 public function __construct(FriendicaPhoto $friendicaPhoto, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
48 parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
50 $this->friendicaPhoto = $friendicaPhoto;
53 protected function rawContent(array $request = [])
55 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
56 $uid = BaseApi::getCurrentUserID();
57 $type = $this->getRequestValue($this->parameters, 'extension', 'json');
58 $request = $this->getRequest([
59 'album' => '', // Get pictures in this album
60 'offset' => 0, // Return results offset by this value
61 'limit' => 50, // Maximum number of results to return. Defaults to 50. Max 500
62 'latest_first' => false, // Whether to reverse the order so newest are first
65 if (empty($request['album'])) {
66 throw new HTTPException\BadRequestException('No album name specified.');
69 $orderDescending = $request['latest_first'];
70 $album = $request['album'];
71 $condition = ["`uid` = ? AND `album` = ?", $uid, $album];
72 $params = ['order' => ['id' => $orderDescending], 'group_by' => ['resource-id']];
74 $limit = $request['limit'];
83 if (!empty($request['offset'])) {
84 $params['limit'] = [$request['offset'], $limit];
86 $params['limit'] = $limit;
89 $photos = Photo::selectToArray(['resource-id'], $condition, $params);
91 $data = ['photo' => []];
92 foreach ($photos as $photo) {
93 $element = $this->friendicaPhoto->createFromId($photo['resource-id'], null, $uid, 'json', false);
95 $element['thumb'] = end($element['link']);
96 unset($element['link']);
99 $thumb = $element['thumb'];
100 unset($element['thumb']);
101 $data['photo'][] = ['@attributes' => $element, '1' => $thumb];
103 $data['photo'][] = $element;
107 $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));