]> git.mxchange.org Git - friendica.git/blob - mod/photos.php
Some more "q" calls handled
[friendica.git] / mod / photos.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Content\Widget;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Addon;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Logger;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Session;
34 use Friendica\Core\System;
35 use Friendica\Database\DBA;
36 use Friendica\DI;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Item;
39 use Friendica\Model\Photo;
40 use Friendica\Model\Post;
41 use Friendica\Model\Profile;
42 use Friendica\Model\Tag;
43 use Friendica\Model\User;
44 use Friendica\Module\BaseProfile;
45 use Friendica\Network\Probe;
46 use Friendica\Object\Image;
47 use Friendica\Protocol\Activity;
48 use Friendica\Util\Crypto;
49 use Friendica\Util\DateTimeFormat;
50 use Friendica\Util\Images;
51 use Friendica\Util\Map;
52 use Friendica\Security\Security;
53 use Friendica\Util\Strings;
54 use Friendica\Util\Temporal;
55 use Friendica\Util\XML;
56 use Friendica\Network\HTTPException;
57
58 function photos_init(App $a) {
59
60         if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
61                 return;
62         }
63
64         Nav::setSelected('home');
65
66         if (DI::args()->getArgc() > 1) {
67                 $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
68                 if (!$owner) {
69                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
70                 }
71
72                 $is_owner = (local_user() && (local_user() == $owner['uid']));
73
74                 $albums = Photo::getAlbums($owner['uid']);
75
76                 $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
77
78                 // add various encodings to the array so we can just loop through and pick them out in a template
79                 $ret = ['success' => false];
80
81                 if ($albums) {
82                         if ($albums_visible) {
83                                 $ret['success'] = true;
84                         }
85
86                         $ret['albums'] = [];
87                         foreach ($albums as $k => $album) {
88                                 //hide profile photos to others
89                                 if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t('Profile Photos')))
90                                         continue;
91                                 $entry = [
92                                         'text'      => $album['album'],
93                                         'total'     => $album['total'],
94                                         'url'       => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
95                                         'urlencode' => urlencode($album['album']),
96                                         'bin2hex'   => bin2hex($album['album'])
97                                 ];
98                                 $ret['albums'][] = $entry;
99                         }
100                 }
101
102                 if (local_user() && $owner['uid'] == local_user()) {
103                         $can_post = true;
104                 } else {
105                         $can_post = false;
106                 }
107
108                 if ($ret['success']) {
109                         $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
110                                 '$nick'     => $owner['nickname'],
111                                 '$title'    => DI::l10n()->t('Photo Albums'),
112                                 '$recent'   => DI::l10n()->t('Recent Photos'),
113                                 '$albums'   => $ret['albums'],
114                                 '$upload'   => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
115                                 '$can_post' => $can_post
116                         ]);
117                 }
118
119                 if (empty(DI::page()['aside'])) {
120                         DI::page()['aside'] = '';
121                 }
122
123                 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
124
125                 if (!empty($photo_albums_widget)) {
126                         DI::page()['aside'] .= $photo_albums_widget;
127                 }
128
129                 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
130
131                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
132                         '$ispublic' => DI::l10n()->t('everybody')
133                 ]);
134         }
135
136         return;
137 }
138
139 function photos_post(App $a)
140 {
141         $user = User::getByNickname(DI::args()->getArgv()[1]);
142         if (!DBA::isResult($user)) {
143                 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
144         }
145
146         $phototypes = Images::supportedTypes();
147
148         $can_post  = false;
149         $visitor   = 0;
150
151         $page_owner_uid = intval($user['uid']);
152         $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
153
154         if (local_user() && (local_user() == $page_owner_uid)) {
155                 $can_post = true;
156         } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
157                 $contact_id = Session::getRemoteContactID($page_owner_uid);
158                 $can_post = true;
159                 $visitor = $contact_id;
160         }
161
162         if (!$can_post) {
163                 notice(DI::l10n()->t('Permission denied.'));
164                 exit();
165         }
166
167         $owner_record = User::getOwnerDataById($page_owner_uid);
168
169         if (!$owner_record) {
170                 notice(DI::l10n()->t('Contact information unavailable'));
171                 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
172                 exit();
173         }
174
175         $aclFormatter = DI::aclFormatter();
176         $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
177         $str_group_allow   = isset($_REQUEST['group_allow'])   ? $aclFormatter->toString($_REQUEST['group_allow'])   : $owner_record['allow_gid'] ?? '';
178         $str_contact_deny  = isset($_REQUEST['contact_deny'])  ? $aclFormatter->toString($_REQUEST['contact_deny'])  : $owner_record['deny_cid']  ?? '';
179         $str_group_deny    = isset($_REQUEST['group_deny'])    ? $aclFormatter->toString($_REQUEST['group_deny'])    : $owner_record['deny_gid']  ?? '';
180
181         $visibility = $_REQUEST['visibility'] ?? '';
182         if ($visibility === 'public') {
183                 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
184                 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
185         } else if ($visibility === 'custom') {
186                 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
187                 // case that would make it public. So we always append the author's contact id to the allowed contacts.
188                 // See https://github.com/friendica/friendica/issues/9672
189                 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
190         }
191
192         if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
193                 if (!Strings::isHex(DI::args()->getArgv()[3])) {
194                         DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
195                 }
196                 $album = hex2bin(DI::args()->getArgv()[3]);
197
198                 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
199                         DI::baseUrl()->redirect($_SESSION['photo_return']);
200                         return; // NOTREACHED
201                 }
202
203                 if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid])) {
204                         notice(DI::l10n()->t('Album not found.'));
205                         DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
206                         return; // NOTREACHED
207                 }
208
209                 // Check if the user has responded to a delete confirmation query
210                 if (!empty($_REQUEST['canceled'])) {
211                         DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
212                 }
213
214                 // RENAME photo album
215                 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
216                 if ($newalbum != $album) {
217                         Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
218                         // Update the photo albums cache
219                         Photo::clearAlbumCache($page_owner_uid);
220
221                         DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
222                         return; // NOTREACHED
223                 }
224
225                 /*
226                  * DELETE all photos filed in a given album
227                  */
228                 if (!empty($_POST['dropalbum'])) {
229                         $res = [];
230
231                         // get the list of photos we are about to delete
232                         if ($visitor) {
233                                 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
234                                         $visitor,
235                                         $page_owner_uid,
236                                         $album
237                                 ));
238                         } else {
239                                 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
240                                         local_user(),
241                                         $album
242                                 ));
243                         }
244
245                         if (DBA::isResult($r)) {
246                                 foreach ($r as $rr) {
247                                         $res[] = $rr['rid'];
248                                 }
249
250                                 // remove the associated photos
251                                 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
252
253                                 // find and delete the corresponding item with all the comments and likes/dislikes
254                                 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
255
256                                 // Update the photo albums cache
257                                 Photo::clearAlbumCache($page_owner_uid);
258                                 notice(DI::l10n()->t('Album successfully deleted'));
259                         } else {
260                                 notice(DI::l10n()->t('Album was empty.'));
261                         }
262                 }
263
264                 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
265         }
266
267         if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
268                 // Check if the user has responded to a delete confirmation query for a single photo
269                 if (!empty($_POST['canceled'])) {
270                         DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
271                 }
272
273                 if (!empty($_POST['delete'])) {
274                         // same as above but remove single photo
275                         if ($visitor) {
276                                 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
277
278                         } else {
279                                 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
280                         }
281
282                         $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
283
284                         if (DBA::isResult($photo)) {
285                                 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
286
287                                 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
288
289                                 // Update the photo albums cache
290                                 Photo::clearAlbumCache($page_owner_uid);
291                         } else {
292                                 notice(DI::l10n()->t('Failed to delete the photo.'));
293                                 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
294                         }
295
296                         DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
297                         return; // NOTREACHED
298                 }
299         }
300
301         if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
302                 $desc        = !empty($_POST['desc'])      ? Strings::escapeTags(trim($_POST['desc']))      : '';
303                 $rawtags     = !empty($_POST['newtag'])    ? Strings::escapeTags(trim($_POST['newtag']))    : '';
304                 $item_id     = !empty($_POST['item_id'])   ? intval($_POST['item_id'])                      : 0;
305                 $albname     = !empty($_POST['albname'])   ? trim($_POST['albname'])                        : '';
306                 $origaname   = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
307
308                 $resource_id = DI::args()->getArgv()[3];
309
310                 if (!strlen($albname)) {
311                         $albname = DateTimeFormat::localNow('Y');
312                 }
313
314                 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
315                         Logger::notice('rotate');
316
317                         $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
318
319                         if (DBA::isResult($photo)) {
320                                 $image = Photo::getImageForPhoto($photo);
321
322                                 if ($image->isValid()) {
323                                         $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
324                                         $image->rotate($rotate_deg);
325
326                                         $width  = $image->getWidth();
327                                         $height = $image->getHeight();
328
329                                         Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
330
331                                         if ($width > 640 || $height > 640) {
332                                                 $image->scaleDown(640);
333                                                 $width  = $image->getWidth();
334                                                 $height = $image->getHeight();
335
336                                                 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
337                                         }
338
339                                         if ($width > 320 || $height > 320) {
340                                                 $image->scaleDown(320);
341                                                 $width  = $image->getWidth();
342                                                 $height = $image->getHeight();
343
344                                                 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
345                                         }
346                                 }
347                         }
348                 }
349
350                 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
351
352                 $photos = DBA::toArray($photos_stmt);
353
354                 if (DBA::isResult($photos)) {
355                         $photo = $photos[0];
356                         $ext = $phototypes[$photo['type']];
357                         Photo::update(
358                                 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
359                                 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
360                         );
361
362                         // Update the photo albums cache if album name was changed
363                         if ($albname !== $origaname) {
364                                 Photo::clearAlbumCache($page_owner_uid);
365                         }
366                         /* Don't make the item visible if the only change was the album name */
367
368                         $visibility = 0;
369                         if ($photo['desc'] !== $desc || strlen($rawtags)) {
370                                 $visibility = 1;
371                         }
372                 }
373
374                 if (DBA::isResult($photos) && !$item_id) {
375                         // Create item container
376                         $title = '';
377                         $uri = Item::newURI($page_owner_uid);
378
379                         $arr = [];
380                         $arr['guid']          = System::createUUID();
381                         $arr['uid']           = $page_owner_uid;
382                         $arr['uri']           = $uri;
383                         $arr['post-type']     = Item::PT_IMAGE;
384                         $arr['wall']          = 1;
385                         $arr['resource-id']   = $photo['resource-id'];
386                         $arr['contact-id']    = $owner_record['id'];
387                         $arr['owner-name']    = $owner_record['name'];
388                         $arr['owner-link']    = $owner_record['url'];
389                         $arr['owner-avatar']  = $owner_record['thumb'];
390                         $arr['author-name']   = $owner_record['name'];
391                         $arr['author-link']   = $owner_record['url'];
392                         $arr['author-avatar'] = $owner_record['thumb'];
393                         $arr['title']         = $title;
394                         $arr['allow_cid']     = $photo['allow_cid'];
395                         $arr['allow_gid']     = $photo['allow_gid'];
396                         $arr['deny_cid']      = $photo['deny_cid'];
397                         $arr['deny_gid']      = $photo['deny_gid'];
398                         $arr['visible']       = $visibility;
399                         $arr['origin']        = 1;
400
401                         $arr['body']          = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
402                                                 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
403                                                 . '[/url]';
404
405                         $item_id = Item::insert($arr);
406                 }
407
408                 if ($item_id) {
409                         $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
410
411                         if (DBA::isResult($item)) {
412                                 $old_inform = $item['inform'];
413                         }
414                 }
415
416                 if (strlen($rawtags)) {
417                         $inform   = '';
418
419                         // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
420                         $x = substr($rawtags, 0, 1);
421                         if ($x !== '@' && $x !== '#') {
422                                 $rawtags = '#' . $rawtags;
423                         }
424
425                         $taginfo = [];
426                         $tags = BBCode::getTags($rawtags);
427
428                         if (count($tags)) {
429                                 foreach ($tags as $tag) {
430                                         if (strpos($tag, '@') === 0) {
431                                                 $profile = '';
432                                                 $contact = null;
433                                                 $name = substr($tag,1);
434
435                                                 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
436                                                         $newname = $name;
437                                                         $links = @Probe::lrdd($name);
438
439                                                         if (count($links)) {
440                                                                 foreach ($links as $link) {
441                                                                         if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
442                                                                                 $profile = $link['@attributes']['href'];
443                                                                         }
444
445                                                                         if ($link['@attributes']['rel'] === 'salmon') {
446                                                                                 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
447
448                                                                                 if (strlen($inform)) {
449                                                                                         $inform .= ',';
450                                                                                 }
451
452                                                                                 $inform .= $salmon;
453                                                                         }
454                                                                 }
455                                                         }
456
457                                                         $taginfo[] = [$newname, $profile, $salmon];
458                                                 } else {
459                                                         $newname = $name;
460                                                         $tagcid = 0;
461
462                                                         if (strrpos($newname, '+')) {
463                                                                 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
464                                                         }
465
466                                                         if ($tagcid) {
467                                                                 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
468                                                         } else {
469                                                                 $newname = str_replace('_',' ',$name);
470
471                                                                 //select someone from this user's contacts by name
472                                                                 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
473                                                                 if (!DBA::isResult($contact)) {
474                                                                         //select someone by attag or nick and the name passed in
475                                                                         $contact = DBA::selectFirst('contact', [],
476                                                                                 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
477                                                                                 ['order' => ['attag' => true]]
478                                                                         );
479                                                                 }
480                                                         }
481
482                                                         if (DBA::isResult($contact)) {
483                                                                 $newname = $contact['name'];
484                                                                 $profile = $contact['url'];
485
486                                                                 $notify = 'cid:' . $contact['id'];
487                                                                 if (strlen($inform)) {
488                                                                         $inform .= ',';
489                                                                 }
490                                                                 $inform .= $notify;
491                                                         }
492                                                 }
493
494                                                 if ($profile) {
495                                                         if (!empty($contact)) {
496                                                                 $taginfo[] = [$newname, $profile, $notify, $contact];
497                                                         } else {
498                                                                 $taginfo[] = [$newname, $profile, $notify, null];
499                                                         }
500
501                                                         $profile = str_replace(',', '%2c', $profile);
502
503                                                         if (!empty($item['uri-id'])) {
504                                                                 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
505                                                         }
506                                                 }
507                                         } elseif (strpos($tag, '#') === 0) {
508                                                 $tagname = substr($tag, 1);
509                                                 if (!empty($item['uri-id'])) {
510                                                         Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
511                                                 }
512                                         }
513                                 }
514                         }
515
516                         $newinform = $old_inform ?? '';
517                         if (strlen($newinform) && strlen($inform)) {
518                                 $newinform .= ',';
519                         }
520                         $newinform .= $inform;
521
522                         $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
523                         $condition = ['id' => $item_id];
524                         Item::update($fields, $condition);
525
526                         $best = 0;
527                         foreach ($photos as $scales) {
528                                 if (intval($scales['scale']) == 2) {
529                                         $best = 2;
530                                         break;
531                                 }
532
533                                 if (intval($scales['scale']) == 4) {
534                                         $best = 4;
535                                         break;
536                                 }
537                         }
538
539                         if (count($taginfo)) {
540                                 foreach ($taginfo as $tagged) {
541                                         $uri = Item::newURI($page_owner_uid);
542
543                                         $arr = [];
544                                         $arr['guid']          = System::createUUID();
545                                         $arr['uid']           = $page_owner_uid;
546                                         $arr['uri']           = $uri;
547                                         $arr['wall']          = 1;
548                                         $arr['contact-id']    = $owner_record['id'];
549                                         $arr['owner-name']    = $owner_record['name'];
550                                         $arr['owner-link']    = $owner_record['url'];
551                                         $arr['owner-avatar']  = $owner_record['thumb'];
552                                         $arr['author-name']   = $owner_record['name'];
553                                         $arr['author-link']   = $owner_record['url'];
554                                         $arr['author-avatar'] = $owner_record['thumb'];
555                                         $arr['title']         = '';
556                                         $arr['allow_cid']     = $photo['allow_cid'];
557                                         $arr['allow_gid']     = $photo['allow_gid'];
558                                         $arr['deny_cid']      = $photo['deny_cid'];
559                                         $arr['deny_gid']      = $photo['deny_gid'];
560                                         $arr['visible']       = 1;
561                                         $arr['verb']          = Activity::TAG;
562                                         $arr['gravity']       = GRAVITY_PARENT;
563                                         $arr['object-type']   = Activity\ObjectType::PERSON;
564                                         $arr['target-type']   = Activity\ObjectType::IMAGE;
565                                         $arr['inform']        = $tagged[2];
566                                         $arr['origin']        = 1;
567                                         $arr['body']          = DI::l10n()->t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . DI::l10n()->t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
568                                         $arr['body'] .= "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
569
570                                         $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
571                                         $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
572                                         if ($tagged[3]) {
573                                                 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
574                                         }
575                                         $arr['object'] .= '</link></object>' . "\n";
576
577                                         $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
578                                                 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
579                                         $arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
580
581                                         Item::insert($arr);
582                                 }
583                         }
584                 }
585                 DI::baseUrl()->redirect($_SESSION['photo_return']);
586                 return; // NOTREACHED
587         }
588
589
590         // default post action - upload a photo
591         Hook::callAll('photo_post_init', $_POST);
592
593         // Determine the album to use
594         $album    = trim($_REQUEST['album'] ?? '');
595         $newalbum = trim($_REQUEST['newalbum'] ?? '');
596
597         Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
598
599         if (!strlen($album)) {
600                 if (strlen($newalbum)) {
601                         $album = $newalbum;
602                 } else {
603                         $album = DateTimeFormat::localNow('Y');
604                 }
605         }
606
607         /*
608          * We create a wall item for every photo, but we don't want to
609          * overwhelm the data stream with a hundred newly uploaded photos.
610          * So we will make the first photo uploaded to this album in the last several hours
611          * visible by default, the rest will become visible over time when and if
612          * they acquire comments, likes, dislikes, and/or tags
613          */
614
615         $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
616
617         if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
618                 $visible = 1;
619         } else {
620                 $visible = 0;
621         }
622
623         if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
624                 $visible = 0;
625         }
626
627         $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
628
629         Hook::callAll('photo_post_file', $ret);
630
631         if (!empty($ret['src']) && !empty($ret['filesize'])) {
632                 $src      = $ret['src'];
633                 $filename = $ret['filename'];
634                 $filesize = $ret['filesize'];
635                 $type     = $ret['type'];
636                 $error    = UPLOAD_ERR_OK;
637         } elseif (!empty($_FILES['userfile'])) {
638                 $src      = $_FILES['userfile']['tmp_name'];
639                 $filename = basename($_FILES['userfile']['name']);
640                 $filesize = intval($_FILES['userfile']['size']);
641                 $type     = $_FILES['userfile']['type'];
642                 $error    = $_FILES['userfile']['error'];
643         } else {
644                 $error    = UPLOAD_ERR_NO_FILE;
645         }
646
647         if ($error !== UPLOAD_ERR_OK) {
648                 switch ($error) {
649                         case UPLOAD_ERR_INI_SIZE:
650                                 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
651                                 break;
652                         case UPLOAD_ERR_FORM_SIZE:
653                                 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
654                                 break;
655                         case UPLOAD_ERR_PARTIAL:
656                                 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
657                                 break;
658                         case UPLOAD_ERR_NO_FILE:
659                                 notice(DI::l10n()->t('Image file is missing'));
660                                 break;
661                         case UPLOAD_ERR_NO_TMP_DIR:
662                         case UPLOAD_ERR_CANT_WRITE:
663                         case UPLOAD_ERR_EXTENSION:
664                                 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
665                                 break;
666                 }
667                 @unlink($src);
668                 $foo = 0;
669                 Hook::callAll('photo_post_end', $foo);
670                 return;
671         }
672
673         $type = Images::getMimeTypeBySource($src, $filename, $type);
674
675         Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
676
677         $maximagesize = DI::config()->get('system', 'maximagesize');
678
679         if ($maximagesize && ($filesize > $maximagesize)) {
680                 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
681                 @unlink($src);
682                 $foo = 0;
683                 Hook::callAll('photo_post_end', $foo);
684                 return;
685         }
686
687         if (!$filesize) {
688                 notice(DI::l10n()->t('Image file is empty.'));
689                 @unlink($src);
690                 $foo = 0;
691                 Hook::callAll('photo_post_end', $foo);
692                 return;
693         }
694
695         Logger::info('loading the contents of ' . $src);
696
697         $imagedata = @file_get_contents($src);
698
699         $image = new Image($imagedata, $type);
700
701         if (!$image->isValid()) {
702                 Logger::info('unable to process image');
703                 notice(DI::l10n()->t('Unable to process image.'));
704                 @unlink($src);
705                 $foo = 0;
706                 Hook::callAll('photo_post_end',$foo);
707                 return;
708         }
709
710         $exif = $image->orient($src);
711         @unlink($src);
712
713         $max_length = DI::config()->get('system', 'max_image_length');
714         if (!$max_length) {
715                 $max_length = MAX_IMAGE_LENGTH;
716         }
717         if ($max_length > 0) {
718                 $image->scaleDown($max_length);
719         }
720
721         $width  = $image->getWidth();
722         $height = $image->getHeight();
723
724         $smallest = 0;
725
726         $resource_id = Photo::newResource();
727
728         $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
729
730         if (!$r) {
731                 Logger::info('image store failed');
732                 notice(DI::l10n()->t('Image upload failed.'));
733                 return;
734         }
735
736         if ($width > 640 || $height > 640) {
737                 $image->scaleDown(640);
738                 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
739                 $smallest = 1;
740         }
741
742         if ($width > 320 || $height > 320) {
743                 $image->scaleDown(320);
744                 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
745                 $smallest = 2;
746         }
747
748         $uri = Item::newURI($page_owner_uid);
749
750         // Create item container
751         $lat = $lon = null;
752         if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
753                 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
754                 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
755         }
756
757         $arr = [];
758         if ($lat && $lon) {
759                 $arr['coord'] = $lat . ' ' . $lon;
760         }
761
762         $arr['guid']          = System::createUUID();
763         $arr['uid']           = $page_owner_uid;
764         $arr['uri']           = $uri;
765         $arr['post-type']     = Item::PT_IMAGE;
766         $arr['wall']          = 1;
767         $arr['resource-id']   = $resource_id;
768         $arr['contact-id']    = $owner_record['id'];
769         $arr['owner-name']    = $owner_record['name'];
770         $arr['owner-link']    = $owner_record['url'];
771         $arr['owner-avatar']  = $owner_record['thumb'];
772         $arr['author-name']   = $owner_record['name'];
773         $arr['author-link']   = $owner_record['url'];
774         $arr['author-avatar'] = $owner_record['thumb'];
775         $arr['title']         = '';
776         $arr['allow_cid']     = $str_contact_allow;
777         $arr['allow_gid']     = $str_group_allow;
778         $arr['deny_cid']      = $str_contact_deny;
779         $arr['deny_gid']      = $str_group_deny;
780         $arr['visible']       = $visible;
781         $arr['origin']        = 1;
782
783         $arr['body']          = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
784                                 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
785                                 . '[/url]';
786
787         $item_id = Item::insert($arr);
788         // Update the photo albums cache
789         Photo::clearAlbumCache($page_owner_uid);
790
791         Hook::callAll('photo_post_end', $item_id);
792
793         // addon uploaders should call "exit()" within the photo_post_end hook
794         // if they do not wish to be redirected
795
796         DI::baseUrl()->redirect($_SESSION['photo_return']);
797         // NOTREACHED
798 }
799
800 function photos_content(App $a)
801 {
802         // URLs:
803         // photos/name
804         // photos/name/upload
805         // photos/name/upload/xxxxx (xxxxx is album name)
806         // photos/name/album/xxxxx
807         // photos/name/album/xxxxx/edit
808         // photos/name/album/xxxxx/drop
809         // photos/name/image/xxxxx
810         // photos/name/image/xxxxx/edit
811         // photos/name/image/xxxxx/drop
812
813         $user = User::getByNickname(DI::args()->getArgv()[1]);
814         if (!DBA::isResult($user)) {
815                 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
816         }
817
818         if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
819                 notice(DI::l10n()->t('Public access denied.'));
820                 return;
821         }
822
823         if (empty($user)) {
824                 notice(DI::l10n()->t('No photos selected'));
825                 return;
826         }
827
828         $profile = Profile::getByUID($user['uid']);
829
830         $phototypes = Images::supportedTypes();
831
832         $_SESSION['photo_return'] = DI::args()->getCommand();
833
834         // Parse arguments
835         $datum = null;
836         if (DI::args()->getArgc() > 3) {
837                 $datatype = DI::args()->getArgv()[2];
838                 $datum = DI::args()->getArgv()[3];
839         } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
840                 $datatype = 'upload';
841         } else {
842                 $datatype = 'summary';
843         }
844
845         if (DI::args()->getArgc() > 4) {
846                 $cmd = DI::args()->getArgv()[4];
847         } else {
848                 $cmd = 'view';
849         }
850
851         // Setup permissions structures
852         $can_post       = false;
853         $visitor        = 0;
854         $contact        = null;
855         $remote_contact = false;
856         $contact_id     = 0;
857         $edit           = '';
858         $drop           = '';
859
860         $owner_uid = $user['uid'];
861
862         $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
863
864         if (local_user() && (local_user() == $owner_uid)) {
865                 $can_post = true;
866         } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
867                 $contact_id = Session::getRemoteContactID($owner_uid);
868                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
869
870                 if (DBA::isResult($contact)) {
871                         $can_post = true;
872                         $remote_contact = true;
873                         $visitor = $contact_id;
874                 }
875         }
876
877         // perhaps they're visiting - but not a community page, so they wouldn't have write access
878         if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
879                 $contact_id = Session::getRemoteContactID($owner_uid);
880
881                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
882
883                 $remote_contact = DBA::isResult($contact);
884         }
885
886         if (!$remote_contact && local_user()) {
887                 $contact_id = $_SESSION['cid'];
888
889                 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
890         }
891
892         if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
893                 notice(DI::l10n()->t('Access to this item is restricted.'));
894                 return;
895         }
896
897         $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
898
899         $o = "";
900
901         // tabs
902         $is_owner = (local_user() && (local_user() == $owner_uid));
903         $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
904
905         // Display upload form
906         if ($datatype === 'upload') {
907                 if (!$can_post) {
908                         notice(DI::l10n()->t('Permission denied.'));
909                         return;
910                 }
911
912                 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
913
914                 $albumselect = '';
915
916                 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '>&lt;current year&gt;</option>';
917                 $albums = Photo::getAlbums($owner_uid);
918                 if (!empty($albums)) {
919                         foreach ($albums as $album) {
920                                 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
921                                         continue;
922                                 }
923                                 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
924                                 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
925                         }
926                 }
927
928                 $uploader = '';
929
930                 $ret = ['post_url' => 'photos/' . $user['nickname'],
931                                 'addon_text' => $uploader,
932                                 'default_upload' => true];
933
934                 Hook::callAll('photo_upload_form',$ret);
935
936                 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
937                 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
938                         '$submit' => DI::l10n()->t('Submit'),
939                 ]);
940
941                 $usage_message = '';
942
943                 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
944
945                 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
946
947                 $o .= Renderer::replaceMacros($tpl,[
948                         '$pagename' => DI::l10n()->t('Upload Photos'),
949                         '$sessid' => session_id(),
950                         '$usage' => $usage_message,
951                         '$nickname' => $user['nickname'],
952                         '$newalbum' => DI::l10n()->t('New album name: '),
953                         '$existalbumtext' => DI::l10n()->t('or select existing album:'),
954                         '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
955                         '$albumselect' => $albumselect,
956                         '$permissions' => DI::l10n()->t('Permissions'),
957                         '$aclselect' => $aclselect_e,
958                         '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
959                         '$alt_uploader' => $ret['addon_text'],
960                         '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
961                         '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
962                         '$uploadurl' => $ret['post_url'],
963
964                         // ACL permissions box
965                         '$return_path' => DI::args()->getQueryString(),
966                 ]);
967
968                 return $o;
969         }
970
971         // Display a single photo album
972         if ($datatype === 'album') {
973                 // if $datum is not a valid hex, redirect to the default page
974                 if (!Strings::isHex($datum)) {
975                         DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
976                 }
977                 $album = hex2bin($datum);
978
979                 $total = 0;
980                 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
981                         AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
982                         $owner_uid,
983                         $album
984                 ));
985                 if (DBA::isResult($r)) {
986                         $total = count($r);
987                 }
988
989                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
990
991                 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
992                 $order_field = $_GET['order'] ?? '';
993                 if ($order_field === 'posted') {
994                         $order = 'ASC';
995                 } else {
996                         $order = 'DESC';
997                 }
998
999                 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1000                         ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1001                         ANY_VALUE(`created`) as `created`
1002                         FROM `photo` WHERE `uid` = ? AND `album` = ?
1003                         AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
1004                         intval($owner_uid),
1005                         DBA::escape($album),
1006                         $pager->getStart(),
1007                         $pager->getItemsPerPage()
1008                 ));
1009
1010                 if ($cmd === 'drop') {
1011                         $drop_url = DI::args()->getQueryString();
1012
1013                         return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1014                                 '$l10n'           => [
1015                                         'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1016                                         'confirm' => DI::l10n()->t('Delete Album'),
1017                                         'cancel'  => DI::l10n()->t('Cancel'),
1018                                 ],
1019                                 '$method'        => 'post',
1020                                 '$confirm_url'   => $drop_url,
1021                                 '$confirm_name'  => 'dropalbum',
1022                                 '$confirm_value' => 'dropalbum',
1023                         ]);
1024                 }
1025
1026                 // edit album name
1027                 if ($cmd === 'edit') {
1028                         if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1029                                 if ($can_post) {
1030                                         $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1031
1032                                         $album_e = $album;
1033
1034                                         $o .= Renderer::replaceMacros($edit_tpl,[
1035                                                 '$nametext' => DI::l10n()->t('New album name: '),
1036                                                 '$nickname' => $user['nickname'],
1037                                                 '$album' => $album_e,
1038                                                 '$hexalbum' => bin2hex($album),
1039                                                 '$submit' => DI::l10n()->t('Submit'),
1040                                                 '$dropsubmit' => DI::l10n()->t('Delete Album')
1041                                         ]);
1042                                 }
1043                         }
1044                 } else {
1045                         if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1046                                 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1047                                 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1048                         }
1049                 }
1050
1051                 if ($order_field === 'posted') {
1052                         $order =  [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1053                 } else {
1054                         $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1055                 }
1056
1057                 $photos = [];
1058
1059                 if (DBA::isResult($r)) {
1060                         // "Twist" is only used for the duepunto theme with style "slackr"
1061                         $twist = false;
1062                         foreach ($r as $rr) {
1063                                 $twist = !$twist;
1064
1065                                 $ext = $phototypes[$rr['type']];
1066
1067                                 $imgalt_e = $rr['filename'];
1068                                 $desc_e = $rr['desc'];
1069
1070                                 $photos[] = [
1071                                         'id' => $rr['id'],
1072                                         'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1073                                         'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1074                                                 . ($order_field === 'posted' ? '?order=posted' : ''),
1075                                         'title' => DI::l10n()->t('View Photo'),
1076                                         'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1077                                         'alt' => $imgalt_e,
1078                                         'desc'=> $desc_e,
1079                                         'ext' => $ext,
1080                                         'hash'=> $rr['resource-id'],
1081                                 ];
1082                         }
1083                 }
1084
1085                 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1086                 $o .= Renderer::replaceMacros($tpl, [
1087                         '$photos' => $photos,
1088                         '$album' => $album,
1089                         '$can_post' => $can_post,
1090                         '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1091                         '$order' => $order,
1092                         '$edit' => $edit,
1093                         '$drop' => $drop,
1094                         '$paginate' => $pager->renderFull($total),
1095                 ]);
1096
1097                 return $o;
1098
1099         }
1100
1101         // Display one photo
1102         if ($datatype === 'image') {
1103                 // fetch image, item containing image, then comments
1104                 $ph = Photo::selectToArray([], ["`uid` = ? AND `resource-id` = ? " . $sql_extra, $owner_uid, $datum], ['order' => ['scale' => true]]);
1105
1106                 if (!DBA::isResult($ph)) {
1107                         if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1108                                 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1109                         } else {
1110                                 notice(DI::l10n()->t('Photo not available'));
1111                         }
1112                         return;
1113                 }
1114
1115                 if ($cmd === 'drop') {
1116                         $drop_url = DI::args()->getQueryString();
1117
1118                         return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1119                                 '$l10n'           => [
1120                                         'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1121                                         'confirm' => DI::l10n()->t('Delete Photo'),
1122                                         'cancel'  => DI::l10n()->t('Cancel'),
1123                                 ],
1124                                 '$method'        => 'post',
1125                                 '$confirm_url'   => $drop_url,
1126                                 '$confirm_name'  => 'delete',
1127                                 '$confirm_value' => 'delete',
1128                         ]);
1129                 }
1130
1131                 $prevlink = '';
1132                 $nextlink = '';
1133
1134                 /*
1135                  * @todo This query is totally bad, the whole functionality has to be changed
1136                  * The query leads to a really intense used index.
1137                  * By now we hide it if someone wants to.
1138                  */
1139                 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1140                         $order_field = $_GET['order'] ?? '';
1141
1142                         if ($order_field === 'posted') {
1143                                 $order = 'ASC';
1144                         } else {
1145                                 $order = 'DESC';
1146                         }
1147
1148                         $prvnxt = Photo::selectToArray(['resource-id'], ["`album` = ? AND `uid` = ? AND `scale` = ?" . $sql_extra, $ph[0]['album'], $owner_uid, 0]);
1149
1150                         if (DBA::isResult($prvnxt)) {
1151                                 $prv = null;
1152                                 $nxt = null;
1153                                 foreach ($prvnxt as $z => $entry) {
1154                                         if ($entry['resource-id'] == $ph[0]['resource-id']) {
1155                                                 $prv = $z - 1;
1156                                                 $nxt = $z + 1;
1157                                                 if ($prv < 0) {
1158                                                         $prv = count($prvnxt) - 1;
1159                                                 }
1160                                                 if ($nxt >= count($prvnxt)) {
1161                                                         $nxt = 0;
1162                                                 }
1163                                                 break;
1164                                         }
1165                                 }
1166
1167                                 if (!is_null($prv)) {
1168                                         $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1169                                 }
1170                                 if (!is_null($nxt)) {
1171                                         $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1172                                 }
1173
1174                                 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1175                                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1176                                         '$prevlink' => $prevlink,
1177                                         '$nextlink' => $nextlink
1178                                 ]);
1179
1180                                 if ($prevlink) {
1181                                         $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1182                                 }
1183
1184                                 if ($nextlink) {
1185                                         $nextlink = [$nextlink, '<div class="icon next"></div>'];
1186                                 }
1187                         }
1188                 }
1189
1190                 if (count($ph) == 1) {
1191                         $hires = $lores = $ph[0];
1192                 }
1193
1194                 if (count($ph) > 1) {
1195                         if ($ph[1]['scale'] == 2) {
1196                                 // original is 640 or less, we can display it directly
1197                                 $hires = $lores = $ph[0];
1198                         } else {
1199                                 $hires = $ph[0];
1200                                 $lores = $ph[1];
1201                         }
1202                 }
1203
1204                 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1205
1206                 $tools = null;
1207
1208                 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1209                         $tools = [];
1210                         if ($cmd === 'edit') {
1211                                 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1212                         } else {
1213                                 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1214                                 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1215                                 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1216                         }
1217
1218                         if (
1219                                 $ph[0]['uid'] == local_user()
1220                                 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1221                         ) {
1222                                 $tools['lock'] = DI::l10n()->t('Private Photo');
1223                         }
1224                 }
1225
1226                 $photo = [
1227                         'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1228                         'title'=> DI::l10n()->t('View Full Size'),
1229                         'src'  => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1230                         'height' => $hires['height'],
1231                         'width' => $hires['width'],
1232                         'album' => $hires['album'],
1233                         'filename' => $hires['filename'],
1234                 ];
1235
1236                 $map = null;
1237                 $link_item = [];
1238                 $total = 0;
1239
1240                 // Do we have an item for this photo?
1241
1242                 // FIXME! - replace following code to display the conversation with our normal
1243                 // conversation functions so that it works correctly and tracks changes
1244                 // in the evolving conversation code.
1245                 // The difference is that we won't be displaying the conversation head item
1246                 // as a "post" but displaying instead the photo it is linked to
1247
1248                 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1249                 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1250                         DBA::escape($datum)
1251                 );
1252                 if (DBA::isResult($linked_items)) {
1253                         // This is a workaround to not being forced to rewrite the while $sql_extra handling
1254                         $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1255                 }
1256
1257                 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1258                         $condition = ["`parent` = ? AND `gravity` = ?",  $link_item['parent'], GRAVITY_COMMENT];
1259                         $total = Post::count($condition);
1260
1261                         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1262
1263                         $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1264                         $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1265
1266                         if (local_user() == $link_item['uid']) {
1267                                 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1268                         }
1269                 }
1270
1271                 if (!empty($link_item['coord'])) {
1272                         $map = Map::byCoordinates($link_item['coord']);
1273                 }
1274
1275                 $tags = null;
1276
1277                 if (!empty($link_item['id'])) {
1278                         $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1279                         $arr = explode(',', $tag_text);
1280                         // parse tags and add links
1281                         $tag_arr = [];
1282                         foreach ($arr as $tag) {
1283                                 $tag_arr[] = [
1284                                         'name' => BBCode::convert($tag),
1285                                         'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1286                                 ];
1287                         }
1288                         $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1289                         if ($cmd === 'edit') {
1290                                 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1291                                 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1292                         }
1293                 }
1294
1295
1296                 $edit = Null;
1297                 if ($cmd === 'edit' && $can_post) {
1298                         $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1299
1300                         $album_e = $ph[0]['album'];
1301                         $caption_e = $ph[0]['desc'];
1302                         $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1303
1304                         $edit = Renderer::replaceMacros($edit_tpl, [
1305                                 '$id' => $ph[0]['id'],
1306                                 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1307                                 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1308                                 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1309                                 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1310                                 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1311                                 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1312
1313                                 '$nickname' => $user['nickname'],
1314                                 '$resource_id' => $ph[0]['resource-id'],
1315                                 '$permissions' => DI::l10n()->t('Permissions'),
1316                                 '$aclselect' => $aclselect_e,
1317
1318                                 '$item_id' => $link_item['id'] ?? 0,
1319                                 '$submit' => DI::l10n()->t('Submit'),
1320                                 '$delete' => DI::l10n()->t('Delete Photo'),
1321
1322                                 // ACL permissions box
1323                                 '$return_path' => DI::args()->getQueryString(),
1324                         ]);
1325                 }
1326
1327                 $like = '';
1328                 $dislike = '';
1329                 $likebuttons = '';
1330                 $comments = '';
1331                 $paginate = '';
1332
1333                 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1334                         $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1335                         $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1336                         $return_path = DI::args()->getCommand();
1337
1338                         if (!DBA::isResult($items)) {
1339                                 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1340                                         /*
1341                                          * Hmmm, code depending on the presence of a particular addon?
1342                                          * This should be better if done by a hook
1343                                          */
1344                                         $qcomment = null;
1345                                         if (Addon::isEnabled('qcomment')) {
1346                                                 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1347                                                 $qcomment = $words ? explode("\n", $words) : [];
1348                                         }
1349
1350                                         $comments .= Renderer::replaceMacros($cmnt_tpl, [
1351                                                 '$return_path' => '',
1352                                                 '$jsreload' => $return_path,
1353                                                 '$id' => $link_item['id'],
1354                                                 '$parent' => $link_item['id'],
1355                                                 '$profile_uid' =>  $owner_uid,
1356                                                 '$mylink' => $contact['url'],
1357                                                 '$mytitle' => DI::l10n()->t('This is you'),
1358                                                 '$myphoto' => $contact['thumb'],
1359                                                 '$comment' => DI::l10n()->t('Comment'),
1360                                                 '$submit' => DI::l10n()->t('Submit'),
1361                                                 '$preview' => DI::l10n()->t('Preview'),
1362                                                 '$loading' => DI::l10n()->t('Loading...'),
1363                                                 '$qcomment' => $qcomment,
1364                                                 '$rand_num' => Crypto::randomDigits(12)
1365                                         ]);
1366                                 }
1367                         }
1368
1369                         $conv_responses = [
1370                                 'like'        => [],
1371                                 'dislike'     => [],
1372                                 'attendyes'   => [],
1373                                 'attendno'    => [],
1374                                 'attendmaybe' => []
1375                         ];
1376
1377                         if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1378                                 unset($conv_responses['dislike']);
1379                         }
1380
1381                         // display comments
1382                         if (DBA::isResult($items)) {
1383                                 foreach ($items as $item) {
1384                                         DI::conversation()->builtinActivityPuller($item, $conv_responses);
1385                                 }
1386
1387                                 if (!empty($conv_responses['like'][$link_item['uri']])) {
1388                                         $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1389                                 }
1390
1391                                 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1392                                         $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1393                                 }
1394
1395                                 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1396                                         /*
1397                                          * Hmmm, code depending on the presence of a particular addon?
1398                                          * This should be better if done by a hook
1399                                          */
1400                                         $qcomment = null;
1401                                         if (Addon::isEnabled('qcomment')) {
1402                                                 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1403                                                 $qcomment = $words ? explode("\n", $words) : [];
1404                                         }
1405
1406                                         $comments .= Renderer::replaceMacros($cmnt_tpl,[
1407                                                 '$return_path' => '',
1408                                                 '$jsreload' => $return_path,
1409                                                 '$id' => $link_item['id'],
1410                                                 '$parent' => $link_item['id'],
1411                                                 '$profile_uid' =>  $owner_uid,
1412                                                 '$mylink' => $contact['url'],
1413                                                 '$mytitle' => DI::l10n()->t('This is you'),
1414                                                 '$myphoto' => $contact['thumb'],
1415                                                 '$comment' => DI::l10n()->t('Comment'),
1416                                                 '$submit' => DI::l10n()->t('Submit'),
1417                                                 '$preview' => DI::l10n()->t('Preview'),
1418                                                 '$qcomment' => $qcomment,
1419                                                 '$rand_num' => Crypto::randomDigits(12)
1420                                         ]);
1421                                 }
1422
1423                                 foreach ($items as $item) {
1424                                         $comment = '';
1425                                         $template = $tpl;
1426
1427                                         $activity = DI::activity();
1428
1429                                         if (($activity->match($item['verb'], Activity::LIKE) ||
1430                                              $activity->match($item['verb'], Activity::DISLIKE)) &&
1431                                             ($item['gravity'] != GRAVITY_PARENT)) {
1432                                                 continue;
1433                                         }
1434
1435                                         $author = ['uid' => 0, 'id' => $item['author-id'],
1436                                                 'network' => $item['author-network'], 'url' => $item['author-link']];
1437                                         $profile_url = Contact::magicLinkByContact($author);
1438                                         if (strpos($profile_url, 'redir/') === 0) {
1439                                                 $sparkle = ' sparkle';
1440                                         } else {
1441                                                 $sparkle = '';
1442                                         }
1443
1444                                         $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1445                                         $drop = [
1446                                                 'dropping' => $dropping,
1447                                                 'pagedrop' => false,
1448                                                 'select' => DI::l10n()->t('Select'),
1449                                                 'delete' => DI::l10n()->t('Delete'),
1450                                         ];
1451
1452                                         $title_e = $item['title'];
1453                                         $body_e = BBCode::convert($item['body']);
1454
1455                                         $comments .= Renderer::replaceMacros($template,[
1456                                                 '$id' => $item['id'],
1457                                                 '$profile_url' => $profile_url,
1458                                                 '$name' => $item['author-name'],
1459                                                 '$thumb' => $item['author-avatar'],
1460                                                 '$sparkle' => $sparkle,
1461                                                 '$title' => $title_e,
1462                                                 '$body' => $body_e,
1463                                                 '$ago' => Temporal::getRelativeDate($item['created']),
1464                                                 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1465                                                 '$drop' => $drop,
1466                                                 '$comment' => $comment
1467                                         ]);
1468
1469                                         if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1470                                                 /*
1471                                                  * Hmmm, code depending on the presence of a particular addon?
1472                                                  * This should be better if done by a hook
1473                                                  */
1474                                                 $qcomment = null;
1475                                                 if (Addon::isEnabled('qcomment')) {
1476                                                         $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1477                                                         $qcomment = $words ? explode("\n", $words) : [];
1478                                                 }
1479
1480                                                 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1481                                                         '$return_path' => '',
1482                                                         '$jsreload' => $return_path,
1483                                                         '$id' => $item['id'],
1484                                                         '$parent' => $item['parent'],
1485                                                         '$profile_uid' =>  $owner_uid,
1486                                                         '$mylink' => $contact['url'],
1487                                                         '$mytitle' => DI::l10n()->t('This is you'),
1488                                                         '$myphoto' => $contact['thumb'],
1489                                                         '$comment' => DI::l10n()->t('Comment'),
1490                                                         '$submit' => DI::l10n()->t('Submit'),
1491                                                         '$preview' => DI::l10n()->t('Preview'),
1492                                                         '$qcomment' => $qcomment,
1493                                                         '$rand_num' => Crypto::randomDigits(12)
1494                                                 ]);
1495                                         }
1496                                 }
1497                         }
1498
1499                         $responses = [];
1500                         foreach ($conv_responses as $verb => $activity) {
1501                                 if (isset($activity[$link_item['uri']])) {
1502                                         $responses[$verb] = $activity[$link_item['uri']];
1503                                 }
1504                         }
1505
1506                         if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1507                                 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1508                                 $likebuttons = Renderer::replaceMacros($like_tpl, [
1509                                         '$id' => $link_item['id'],
1510                                         '$like' => DI::l10n()->t('Like'),
1511                                         '$like_title' => DI::l10n()->t('I like this (toggle)'),
1512                                         '$dislike' => DI::l10n()->t('Dislike'),
1513                                         '$wait' => DI::l10n()->t('Please wait'),
1514                                         '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1515                                         '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1516                                         '$responses' => $responses,
1517                                         '$return_path' => DI::args()->getQueryString(),
1518                                 ]);
1519                         }
1520
1521                         $paginate = $pager->renderFull($total);
1522                 }
1523
1524                 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1525                 $o .= Renderer::replaceMacros($photo_tpl, [
1526                         '$id' => $ph[0]['id'],
1527                         '$album' => [$album_link, $ph[0]['album']],
1528                         '$tools' => $tools,
1529                         '$photo' => $photo,
1530                         '$prevlink' => $prevlink,
1531                         '$nextlink' => $nextlink,
1532                         '$desc' => $ph[0]['desc'],
1533                         '$tags' => $tags,
1534                         '$edit' => $edit,
1535                         '$map' => $map,
1536                         '$map_text' => DI::l10n()->t('Map'),
1537                         '$likebuttons' => $likebuttons,
1538                         '$like' => $like,
1539                         '$dislike' => $dislike,
1540                         '$comments' => $comments,
1541                         '$paginate' => $paginate,
1542                 ]);
1543
1544                 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1545                 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1546                 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1547                 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1548                 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1549
1550                 return $o;
1551         }
1552
1553         // Default - show recent photos with upload link (if applicable)
1554         //$o = '';
1555         $total = 0;
1556         $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)
1557                 $sql_extra GROUP BY `resource-id`",
1558                 $user['uid'],
1559                 Photo::CONTACT_PHOTOS,
1560                 DI::l10n()->t(Photo::CONTACT_PHOTOS)
1561         ));
1562         if (DBA::isResult($r)) {
1563                 $total = count($r);
1564         }
1565
1566         $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1567
1568         $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1569                 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1570                 ANY_VALUE(`created`) AS `created` FROM `photo`
1571                 WHERE `uid` = ? AND NOT `album` IN (?, ?)
1572                 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
1573                 $user['uid'],
1574                 Photo::CONTACT_PHOTOS,
1575                 DI::l10n()->t(Photo::CONTACT_PHOTOS),
1576                 $pager->getStart(),
1577                 $pager->getItemsPerPage()
1578         ));
1579
1580         $photos = [];
1581         if (DBA::isResult($r)) {
1582                 // "Twist" is only used for the duepunto theme with style "slackr"
1583                 $twist = false;
1584                 foreach ($r as $rr) {
1585                         //hide profile photos to others
1586                         if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1587                                 continue;
1588                         }
1589
1590                         $twist = !$twist;
1591                         $ext = $phototypes[$rr['type']];
1592
1593                         $alt_e = $rr['filename'];
1594                         $name_e = $rr['album'];
1595
1596                         $photos[] = [
1597                                 'id'    => $rr['id'],
1598                                 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1599                                 'link'  => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1600                                 'title' => DI::l10n()->t('View Photo'),
1601                                 'src'   => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1602                                 'alt'   => $alt_e,
1603                                 'album' => [
1604                                         'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1605                                         'name' => $name_e,
1606                                         'alt'  => DI::l10n()->t('View Album'),
1607                                 ],
1608
1609                         ];
1610                 }
1611         }
1612
1613         $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1614         $o .= Renderer::replaceMacros($tpl, [
1615                 '$title' => DI::l10n()->t('Recent Photos'),
1616                 '$can_post' => $can_post,
1617                 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1618                 '$photos' => $photos,
1619                 '$paginate' => $pager->renderFull($total),
1620         ]);
1621
1622         return $o;
1623 }