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