diff --git a/src/Model/Item.php b/src/Model/Item.php index 69b1595c20..8dce7a7880 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3096,7 +3096,7 @@ class Item ]; Hook::callAll('prepare_body', $hook_data); $s = $hook_data['html']; - + unset($hook_data); if (!$attach) { @@ -3146,18 +3146,18 @@ class Item */ public static function makeImageGrid(array $images): string { - $landscapeimages = array(); - $portraitimages = array(); + $landscapeimages = []; + $portraitimages = []; foreach ($images as $image) { ($image['attachment']['width'] > $image['attachment']['height']) ? ($landscapeimages[] = $image) : ($portraitimages[] = $image); } // Image for first column (fc) and second column (sc) - $images_fc = array(); - $images_sc = array(); - $lcount = count($landscapeimages); - $pcount = count($portraitimages); + $images_fc = []; + $images_sc = []; + $lcount = count($landscapeimages); + $pcount = count($portraitimages); if ($lcount == 0 || $pcount == 0) { if ($lcount == 0) { // only portrait @@ -3424,9 +3424,8 @@ class Item $media = ''; if (count($images) > 1) { $media = self::makeImageGrid($images); - } - elseif (count($images) == 1) { - $media = $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [ + } elseif (count($images) == 1) { + $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/image.tpl'), [ '$image' => $images[0], ]); } diff --git a/src/Module/Api/Friendica/Photo/Create.php b/src/Module/Api/Friendica/Photo/Create.php index bb3dc63b22..1f60998b7b 100644 --- a/src/Module/Api/Friendica/Photo/Create.php +++ b/src/Module/Api/Friendica/Photo/Create.php @@ -64,8 +64,8 @@ class Create extends BaseApi // do several checks on input parameters // we do not allow calls without album string - if ($album == null) { - throw new HTTPException\BadRequestException('no albumname specified'); + if ($album === null) { + throw new HTTPException\BadRequestException('no album name specified'); } // error if no media posted in create-mode @@ -88,6 +88,7 @@ class Create extends BaseApi // return success of updating or error message if (!empty($photo)) { + Photo::clearAlbumCache($uid); $data = ['photo' => $this->friendicaPhoto->createFromId($photo['resource_id'], null, $uid, $type)]; $this->response->exit('photo_create', $data, $this->parameters['extension'] ?? null); } else { diff --git a/src/Module/Api/Friendica/Photo/Delete.php b/src/Module/Api/Friendica/Photo/Delete.php index e8dabe3a1f..64cc2e03ae 100644 --- a/src/Module/Api/Friendica/Photo/Delete.php +++ b/src/Module/Api/Friendica/Photo/Delete.php @@ -60,7 +60,7 @@ class Delete extends BaseApi // to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion) $condition = ['uid' => $uid, 'resource-id' => $request['photo_id'], 'post-type' => Item::PT_IMAGE, 'origin' => true]; Item::deleteForUser($condition, $uid); - + Photo::clearAlbumCache($uid); $result = ['result' => 'deleted', 'message' => 'photo with id `' . $request['photo_id'] . '` has been deleted from server.']; $this->response->exit('photo_delete', ['$result' => $result], $this->parameters['extension'] ?? null); } else { diff --git a/src/Module/Api/Friendica/Photo/Update.php b/src/Module/Api/Friendica/Photo/Update.php index 44fd554b09..83ceb7a5c5 100644 --- a/src/Module/Api/Friendica/Photo/Update.php +++ b/src/Module/Api/Friendica/Photo/Update.php @@ -135,6 +135,7 @@ class Update extends BaseApi // return success of updating or error message if ($result) { + Photo::clearAlbumCache($uid); $answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.']; $this->response->exit('photo_update', ['$result' => $answer], $this->parameters['extension'] ?? null); return; diff --git a/src/Module/Api/Friendica/Photoalbum/Delete.php b/src/Module/Api/Friendica/Photoalbum/Delete.php index 4215ddda7f..76062b2fde 100644 --- a/src/Module/Api/Friendica/Photoalbum/Delete.php +++ b/src/Module/Api/Friendica/Photoalbum/Delete.php @@ -66,6 +66,7 @@ class Delete extends BaseApi // return success of deletion or error message if ($result) { + Photo::clearAlbumCache($uid); $answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.']; $this->response->exit('photoalbum_delete', ['$result' => $answer], $this->parameters['extension'] ?? null); } else { diff --git a/src/Module/Api/Friendica/Photoalbum/Index.php b/src/Module/Api/Friendica/Photoalbum/Index.php new file mode 100644 index 0000000000..83fbb5d3d3 --- /dev/null +++ b/src/Module/Api/Friendica/Photoalbum/Index.php @@ -0,0 +1,52 @@ +. + * + */ + +namespace Friendica\Module\Api\Friendica\Photoalbum; + +use Friendica\Model\Photo; +use Friendica\Module\BaseApi; + +/** + * api/friendica/photoalbum + * + * @package Friendica\Module\Api\Friendica\Photoalbum + */ +class Index extends BaseApi +{ + protected function rawContent(array $request = []) + { + self::checkAllowedScope(self::SCOPE_READ); + $uid = self::getCurrentUserID(); + + $albums = Photo::getAlbums($uid); + + $items = []; + foreach ($albums as $album) { + $items[] = [ + 'name' => $album['album'], + 'created' => $album['created'], + 'count' => $album['total'], + ]; + } + + $this->response->exit('albums', ['albums' => $items], $this->parameters['extension'] ?? null); + } +} diff --git a/src/Module/Api/Friendica/Photoalbum/Show.php b/src/Module/Api/Friendica/Photoalbum/Show.php new file mode 100644 index 0000000000..1a50416ecb --- /dev/null +++ b/src/Module/Api/Friendica/Photoalbum/Show.php @@ -0,0 +1,109 @@ +. + * + */ + +namespace Friendica\Module\Api\Friendica\Photoalbum; + +use Friendica\App; +use Friendica\Core\L10n; +use Friendica\Factory\Api\Friendica\Photo as FriendicaPhoto; +use Friendica\Model\Contact; +use Friendica\Model\Photo; +use Friendica\Module\Api\ApiResponse; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +/** + * api/friendica/photoalbum/:name + * + * @package Friendica\Module\Api\Friendica\Photoalbum + */ +class Show extends BaseApi +{ + /** @var FriendicaPhoto */ + private $friendicaPhoto; + + + 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 = []) + { + parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->friendicaPhoto = $friendicaPhoto; + } + + protected function rawContent(array $request = []) + { + BaseApi::checkAllowedScope(BaseApi::SCOPE_READ); + $uid = BaseApi::getCurrentUserID(); + $type = $this->getRequestValue($this->parameters, 'extension', 'json'); + $request = $this->getRequest([ + 'album' => '', // Get pictures in this album + 'offset' => 0, // Return results offset by this value + 'limit' => 50, // Maximum number of results to return. Defaults to 50. Max 500 + 'latest_first' => false, // Whether to reverse the order so newest are first + ], $request); + + if (empty($request['album'])) { + throw new HTTPException\BadRequestException('No album name specified.'); + } + + $orderDescending = $request['latest_first']; + $album = $request['album']; + $condition = ["`uid` = ? AND `album` = ?", $uid, $album]; + $params = ['order' => ['id' => $orderDescending], 'group_by' => ['resource-id']]; + + $limit = $request['limit']; + if ($limit > 500) { + $limit = 500; + } + + if ($limit <= 0) { + $limit = 1; + } + + if (!empty($request['offset'])) { + $params['limit'] = [$request['offset'], $limit]; + } else { + $params['limit'] = $limit; + } + + $photos = Photo::selectToArray(['resource-id'], $condition, $params); + + $data = ['photo' => []]; + foreach ($photos as $photo) { + $element = $this->friendicaPhoto->createFromId($photo['resource-id'], null, $uid, 'json', false); + + $element['thumb'] = end($element['link']); + unset($element['link']); + + if ($type == 'xml') { + $thumb = $element['thumb']; + unset($element['thumb']); + $data['photo'][] = ['@attributes' => $element, '1' => $thumb]; + } else { + $data['photo'][] = $element; + } + } + + $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid)); + } +} diff --git a/src/Module/Api/Friendica/Photoalbum/Update.php b/src/Module/Api/Friendica/Photoalbum/Update.php index 0eca5b22ee..3fa01fe1b4 100644 --- a/src/Module/Api/Friendica/Photoalbum/Update.php +++ b/src/Module/Api/Friendica/Photoalbum/Update.php @@ -58,6 +58,7 @@ class Update extends BaseApi // return success of updating or error message if ($result) { + Photo::clearAlbumCache($uid); $answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.']; $this->response->exit('photoalbum_update', ['$result' => $answer], $this->parameters['extension'] ?? null); } else { diff --git a/static/routes.config.php b/static/routes.config.php index 70d230c2a2..276bbc7c87 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -93,6 +93,8 @@ $apiRoutes = [ '/group_delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Delete::class, [ R::POST]], '/group_update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Update::class, [ R::POST]], '/profile/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Profile\Show::class, [R::GET ]], + '/photoalbums[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Index::class, [R::GET ]], + '/photoalbum[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Show::class, [R::GET ]], '/photoalbum/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Delete::class, [ R::POST]], '/photoalbum/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Update::class, [ R::POST]], '/photos/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photo\Lists::class, [R::GET ]], diff --git a/view/global.css b/view/global.css index 81a1ba2095..d327da0c2c 100644 --- a/view/global.css +++ b/view/global.css @@ -687,25 +687,22 @@ audio { .imagegrid-row { display: -ms-flexbox; /* IE10 */ display: flex; - -ms-flex-wrap: wrap; /* IE10 */ - flex-wrap: wrap; - padding: 0 4px; - box-sizing: border-box; + margin-top: 1em; + column-gap: 5px; } -/* Create four equal columns that sits next to each other */ .imagegrid-column { -ms-flex: 50%; /* IE10 */ flex: 50%; - max-width: 50%; - padding: 0 4px; - box-sizing: border-box; + display: -ms-flexbox; /* IE10 */ + display: flex; + flex-direction: column; + row-gap: 5px; } .imagegrid-column img { - margin-top: 8px; - vertical-align: middle; - width: 100%; + -ms-flex: 50%; /* IE10 */ + flex: 50%; } /** * Image grid settings END diff --git a/view/templates/content/image.tpl b/view/templates/content/image.tpl index 2885d869fb..92a37915ff 100644 --- a/view/templates/content/image.tpl +++ b/view/templates/content/image.tpl @@ -3,4 +3,3 @@ {{else}} {{$image.attachment.description}} {{/if}} -