]> git.mxchange.org Git - friendica.git/blob - mod/photos.php
Merge pull request #10795 from annando/contact-media
[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                                 '$l10n'           => [
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                                         'cancel'  => DI::l10n()->t('Cancel'),
1022                                 ],
1023                                 '$method'        => 'post',
1024                                 '$confirm_url'   => $drop_url,
1025                                 '$confirm_name'  => 'dropalbum',
1026                                 '$confirm_value' => 'dropalbum',
1027                         ]);
1028                 }
1029
1030                 // edit album name
1031                 if ($cmd === 'edit') {
1032                         if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1033                                 if ($can_post) {
1034                                         $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1035
1036                                         $album_e = $album;
1037
1038                                         $o .= Renderer::replaceMacros($edit_tpl,[
1039                                                 '$nametext' => DI::l10n()->t('New album name: '),
1040                                                 '$nickname' => $user['nickname'],
1041                                                 '$album' => $album_e,
1042                                                 '$hexalbum' => bin2hex($album),
1043                                                 '$submit' => DI::l10n()->t('Submit'),
1044                                                 '$dropsubmit' => DI::l10n()->t('Delete Album')
1045                                         ]);
1046                                 }
1047                         }
1048                 } else {
1049                         if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1050                                 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1051                                 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1052                         }
1053                 }
1054
1055                 if ($order_field === 'posted') {
1056                         $order =  [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1057                 } else {
1058                         $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1059                 }
1060
1061                 $photos = [];
1062
1063                 if (DBA::isResult($r)) {
1064                         // "Twist" is only used for the duepunto theme with style "slackr"
1065                         $twist = false;
1066                         foreach ($r as $rr) {
1067                                 $twist = !$twist;
1068
1069                                 $ext = $phototypes[$rr['type']];
1070
1071                                 $imgalt_e = $rr['filename'];
1072                                 $desc_e = $rr['desc'];
1073
1074                                 $photos[] = [
1075                                         'id' => $rr['id'],
1076                                         'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1077                                         'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1078                                                 . ($order_field === 'posted' ? '?order=posted' : ''),
1079                                         'title' => DI::l10n()->t('View Photo'),
1080                                         'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1081                                         'alt' => $imgalt_e,
1082                                         'desc'=> $desc_e,
1083                                         'ext' => $ext,
1084                                         'hash'=> $rr['resource-id'],
1085                                 ];
1086                         }
1087                 }
1088
1089                 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1090                 $o .= Renderer::replaceMacros($tpl, [
1091                         '$photos' => $photos,
1092                         '$album' => $album,
1093                         '$can_post' => $can_post,
1094                         '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1095                         '$order' => $order,
1096                         '$edit' => $edit,
1097                         '$drop' => $drop,
1098                         '$paginate' => $pager->renderFull($total),
1099                 ]);
1100
1101                 return $o;
1102
1103         }
1104
1105         // Display one photo
1106         if ($datatype === 'image') {
1107                 // fetch image, item containing image, then comments
1108                 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1109                         $sql_extra ORDER BY `scale` ASC ",
1110                         intval($owner_uid),
1111                         DBA::escape($datum)
1112                 );
1113
1114                 if (!DBA::isResult($ph)) {
1115                         if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1116                                 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1117                         } else {
1118                                 notice(DI::l10n()->t('Photo not available'));
1119                         }
1120                         return;
1121                 }
1122
1123                 if ($cmd === 'drop') {
1124                         $drop_url = DI::args()->getQueryString();
1125
1126                         return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1127                                 '$l10n'           => [
1128                                         'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1129                                         'confirm' => DI::l10n()->t('Delete Photo'),
1130                                         'cancel'  => DI::l10n()->t('Cancel'),
1131                                 ],
1132                                 '$method'        => 'post',
1133                                 '$confirm_url'   => $drop_url,
1134                                 '$confirm_name'  => 'delete',
1135                                 '$confirm_value' => 'delete',
1136                         ]);
1137                 }
1138
1139                 $prevlink = '';
1140                 $nextlink = '';
1141
1142                 /*
1143                  * @todo This query is totally bad, the whole functionality has to be changed
1144                  * The query leads to a really intense used index.
1145                  * By now we hide it if someone wants to.
1146                  */
1147                 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1148                         $order_field = $_GET['order'] ?? '';
1149
1150                         if ($order_field === 'posted') {
1151                                 $order = 'ASC';
1152                         } else {
1153                                 $order = 'DESC';
1154                         }
1155
1156                         $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1157                                 $sql_extra ORDER BY `created` $order ",
1158                                 DBA::escape($ph[0]['album']),
1159                                 intval($owner_uid)
1160                         );
1161
1162                         if (DBA::isResult($prvnxt)) {
1163                                 $prv = null;
1164                                 $nxt = null;
1165                                 foreach ($prvnxt as $z => $entry) {
1166                                         if ($entry['resource-id'] == $ph[0]['resource-id']) {
1167                                                 $prv = $z - 1;
1168                                                 $nxt = $z + 1;
1169                                                 if ($prv < 0) {
1170                                                         $prv = count($prvnxt) - 1;
1171                                                 }
1172                                                 if ($nxt >= count($prvnxt)) {
1173                                                         $nxt = 0;
1174                                                 }
1175                                                 break;
1176                                         }
1177                                 }
1178
1179                                 if (!is_null($prv)) {
1180                                         $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1181                                 }
1182                                 if (!is_null($nxt)) {
1183                                         $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1184                                 }
1185
1186                                 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1187                                 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1188                                         '$prevlink' => $prevlink,
1189                                         '$nextlink' => $nextlink
1190                                 ]);
1191
1192                                 if ($prevlink) {
1193                                         $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1194                                 }
1195
1196                                 if ($nextlink) {
1197                                         $nextlink = [$nextlink, '<div class="icon next"></div>'];
1198                                 }
1199                         }
1200                 }
1201
1202                 if (count($ph) == 1) {
1203                         $hires = $lores = $ph[0];
1204                 }
1205
1206                 if (count($ph) > 1) {
1207                         if ($ph[1]['scale'] == 2) {
1208                                 // original is 640 or less, we can display it directly
1209                                 $hires = $lores = $ph[0];
1210                         } else {
1211                                 $hires = $ph[0];
1212                                 $lores = $ph[1];
1213                         }
1214                 }
1215
1216                 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1217
1218                 $tools = null;
1219
1220                 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1221                         $tools = [];
1222                         if ($cmd === 'edit') {
1223                                 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1224                         } else {
1225                                 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1226                                 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1227                                 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1228                         }
1229
1230                         if (
1231                                 $ph[0]['uid'] == local_user()
1232                                 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1233                         ) {
1234                                 $tools['lock'] = DI::l10n()->t('Private Photo');
1235                         }
1236                 }
1237
1238                 $photo = [
1239                         'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1240                         'title'=> DI::l10n()->t('View Full Size'),
1241                         'src'  => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1242                         'height' => $hires['height'],
1243                         'width' => $hires['width'],
1244                         'album' => $hires['album'],
1245                         'filename' => $hires['filename'],
1246                 ];
1247
1248                 $map = null;
1249                 $link_item = [];
1250                 $total = 0;
1251
1252                 // Do we have an item for this photo?
1253
1254                 // FIXME! - replace following code to display the conversation with our normal
1255                 // conversation functions so that it works correctly and tracks changes
1256                 // in the evolving conversation code.
1257                 // The difference is that we won't be displaying the conversation head item
1258                 // as a "post" but displaying instead the photo it is linked to
1259
1260                 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1261                 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1262                         DBA::escape($datum)
1263                 );
1264                 if (DBA::isResult($linked_items)) {
1265                         // This is a workaround to not being forced to rewrite the while $sql_extra handling
1266                         $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1267                 }
1268
1269                 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1270                         $condition = ["`parent` = ? AND `gravity` = ?",  $link_item['parent'], GRAVITY_COMMENT];
1271                         $total = Post::count($condition);
1272
1273                         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1274
1275                         $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1276                         $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1277
1278                         if (local_user() == $link_item['uid']) {
1279                                 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1280                         }
1281                 }
1282
1283                 if (!empty($link_item['coord'])) {
1284                         $map = Map::byCoordinates($link_item['coord']);
1285                 }
1286
1287                 $tags = null;
1288
1289                 if (!empty($link_item['id'])) {
1290                         $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1291                         $arr = explode(',', $tag_text);
1292                         // parse tags and add links
1293                         $tag_arr = [];
1294                         foreach ($arr as $tag) {
1295                                 $tag_arr[] = [
1296                                         'name' => BBCode::convert($tag),
1297                                         'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1298                                 ];
1299                         }
1300                         $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1301                         if ($cmd === 'edit') {
1302                                 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1303                                 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1304                         }
1305                 }
1306
1307
1308                 $edit = Null;
1309                 if ($cmd === 'edit' && $can_post) {
1310                         $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1311
1312                         $album_e = $ph[0]['album'];
1313                         $caption_e = $ph[0]['desc'];
1314                         $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1315
1316                         $edit = Renderer::replaceMacros($edit_tpl, [
1317                                 '$id' => $ph[0]['id'],
1318                                 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1319                                 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1320                                 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1321                                 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1322                                 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1323                                 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1324
1325                                 '$nickname' => $user['nickname'],
1326                                 '$resource_id' => $ph[0]['resource-id'],
1327                                 '$permissions' => DI::l10n()->t('Permissions'),
1328                                 '$aclselect' => $aclselect_e,
1329
1330                                 '$item_id' => $link_item['id'] ?? 0,
1331                                 '$submit' => DI::l10n()->t('Submit'),
1332                                 '$delete' => DI::l10n()->t('Delete Photo'),
1333
1334                                 // ACL permissions box
1335                                 '$return_path' => DI::args()->getQueryString(),
1336                         ]);
1337                 }
1338
1339                 $like = '';
1340                 $dislike = '';
1341                 $likebuttons = '';
1342                 $comments = '';
1343                 $paginate = '';
1344
1345                 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1346                         $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1347                         $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1348                         $return_path = DI::args()->getCommand();
1349
1350                         if (!DBA::isResult($items)) {
1351                                 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1352                                         /*
1353                                          * Hmmm, code depending on the presence of a particular addon?
1354                                          * This should be better if done by a hook
1355                                          */
1356                                         $qcomment = null;
1357                                         if (Addon::isEnabled('qcomment')) {
1358                                                 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1359                                                 $qcomment = $words ? explode("\n", $words) : [];
1360                                         }
1361
1362                                         $comments .= Renderer::replaceMacros($cmnt_tpl, [
1363                                                 '$return_path' => '',
1364                                                 '$jsreload' => $return_path,
1365                                                 '$id' => $link_item['id'],
1366                                                 '$parent' => $link_item['id'],
1367                                                 '$profile_uid' =>  $owner_uid,
1368                                                 '$mylink' => $contact['url'],
1369                                                 '$mytitle' => DI::l10n()->t('This is you'),
1370                                                 '$myphoto' => $contact['thumb'],
1371                                                 '$comment' => DI::l10n()->t('Comment'),
1372                                                 '$submit' => DI::l10n()->t('Submit'),
1373                                                 '$preview' => DI::l10n()->t('Preview'),
1374                                                 '$loading' => DI::l10n()->t('Loading...'),
1375                                                 '$qcomment' => $qcomment,
1376                                                 '$rand_num' => Crypto::randomDigits(12)
1377                                         ]);
1378                                 }
1379                         }
1380
1381                         $conv_responses = [
1382                                 'like'        => [],
1383                                 'dislike'     => [],
1384                                 'attendyes'   => [],
1385                                 'attendno'    => [],
1386                                 'attendmaybe' => []
1387                         ];
1388
1389                         if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1390                                 unset($conv_responses['dislike']);
1391                         }
1392
1393                         // display comments
1394                         if (DBA::isResult($items)) {
1395                                 foreach ($items as $item) {
1396                                         DI::conversation()->builtinActivityPuller($item, $conv_responses);
1397                                 }
1398
1399                                 if (!empty($conv_responses['like'][$link_item['uri']])) {
1400                                         $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1401                                 }
1402
1403                                 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1404                                         $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1405                                 }
1406
1407                                 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1408                                         /*
1409                                          * Hmmm, code depending on the presence of a particular addon?
1410                                          * This should be better if done by a hook
1411                                          */
1412                                         $qcomment = null;
1413                                         if (Addon::isEnabled('qcomment')) {
1414                                                 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1415                                                 $qcomment = $words ? explode("\n", $words) : [];
1416                                         }
1417
1418                                         $comments .= Renderer::replaceMacros($cmnt_tpl,[
1419                                                 '$return_path' => '',
1420                                                 '$jsreload' => $return_path,
1421                                                 '$id' => $link_item['id'],
1422                                                 '$parent' => $link_item['id'],
1423                                                 '$profile_uid' =>  $owner_uid,
1424                                                 '$mylink' => $contact['url'],
1425                                                 '$mytitle' => DI::l10n()->t('This is you'),
1426                                                 '$myphoto' => $contact['thumb'],
1427                                                 '$comment' => DI::l10n()->t('Comment'),
1428                                                 '$submit' => DI::l10n()->t('Submit'),
1429                                                 '$preview' => DI::l10n()->t('Preview'),
1430                                                 '$qcomment' => $qcomment,
1431                                                 '$rand_num' => Crypto::randomDigits(12)
1432                                         ]);
1433                                 }
1434
1435                                 foreach ($items as $item) {
1436                                         $comment = '';
1437                                         $template = $tpl;
1438
1439                                         $activity = DI::activity();
1440
1441                                         if (($activity->match($item['verb'], Activity::LIKE) ||
1442                                              $activity->match($item['verb'], Activity::DISLIKE)) &&
1443                                             ($item['gravity'] != GRAVITY_PARENT)) {
1444                                                 continue;
1445                                         }
1446
1447                                         $author = ['uid' => 0, 'id' => $item['author-id'],
1448                                                 'network' => $item['author-network'], 'url' => $item['author-link']];
1449                                         $profile_url = Contact::magicLinkByContact($author);
1450                                         if (strpos($profile_url, 'redir/') === 0) {
1451                                                 $sparkle = ' sparkle';
1452                                         } else {
1453                                                 $sparkle = '';
1454                                         }
1455
1456                                         $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1457                                         $drop = [
1458                                                 'dropping' => $dropping,
1459                                                 'pagedrop' => false,
1460                                                 'select' => DI::l10n()->t('Select'),
1461                                                 'delete' => DI::l10n()->t('Delete'),
1462                                         ];
1463
1464                                         $title_e = $item['title'];
1465                                         $body_e = BBCode::convert($item['body']);
1466
1467                                         $comments .= Renderer::replaceMacros($template,[
1468                                                 '$id' => $item['id'],
1469                                                 '$profile_url' => $profile_url,
1470                                                 '$name' => $item['author-name'],
1471                                                 '$thumb' => $item['author-avatar'],
1472                                                 '$sparkle' => $sparkle,
1473                                                 '$title' => $title_e,
1474                                                 '$body' => $body_e,
1475                                                 '$ago' => Temporal::getRelativeDate($item['created']),
1476                                                 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1477                                                 '$drop' => $drop,
1478                                                 '$comment' => $comment
1479                                         ]);
1480
1481                                         if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1482                                                 /*
1483                                                  * Hmmm, code depending on the presence of a particular addon?
1484                                                  * This should be better if done by a hook
1485                                                  */
1486                                                 $qcomment = null;
1487                                                 if (Addon::isEnabled('qcomment')) {
1488                                                         $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1489                                                         $qcomment = $words ? explode("\n", $words) : [];
1490                                                 }
1491
1492                                                 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1493                                                         '$return_path' => '',
1494                                                         '$jsreload' => $return_path,
1495                                                         '$id' => $item['id'],
1496                                                         '$parent' => $item['parent'],
1497                                                         '$profile_uid' =>  $owner_uid,
1498                                                         '$mylink' => $contact['url'],
1499                                                         '$mytitle' => DI::l10n()->t('This is you'),
1500                                                         '$myphoto' => $contact['thumb'],
1501                                                         '$comment' => DI::l10n()->t('Comment'),
1502                                                         '$submit' => DI::l10n()->t('Submit'),
1503                                                         '$preview' => DI::l10n()->t('Preview'),
1504                                                         '$qcomment' => $qcomment,
1505                                                         '$rand_num' => Crypto::randomDigits(12)
1506                                                 ]);
1507                                         }
1508                                 }
1509                         }
1510
1511                         $responses = [];
1512                         foreach ($conv_responses as $verb => $activity) {
1513                                 if (isset($activity[$link_item['uri']])) {
1514                                         $responses[$verb] = $activity[$link_item['uri']];
1515                                 }
1516                         }
1517
1518                         if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1519                                 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1520                                 $likebuttons = Renderer::replaceMacros($like_tpl, [
1521                                         '$id' => $link_item['id'],
1522                                         '$like' => DI::l10n()->t('Like'),
1523                                         '$like_title' => DI::l10n()->t('I like this (toggle)'),
1524                                         '$dislike' => DI::l10n()->t('Dislike'),
1525                                         '$wait' => DI::l10n()->t('Please wait'),
1526                                         '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1527                                         '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1528                                         '$responses' => $responses,
1529                                         '$return_path' => DI::args()->getQueryString(),
1530                                 ]);
1531                         }
1532
1533                         $paginate = $pager->renderFull($total);
1534                 }
1535
1536                 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1537                 $o .= Renderer::replaceMacros($photo_tpl, [
1538                         '$id' => $ph[0]['id'],
1539                         '$album' => [$album_link, $ph[0]['album']],
1540                         '$tools' => $tools,
1541                         '$photo' => $photo,
1542                         '$prevlink' => $prevlink,
1543                         '$nextlink' => $nextlink,
1544                         '$desc' => $ph[0]['desc'],
1545                         '$tags' => $tags,
1546                         '$edit' => $edit,
1547                         '$map' => $map,
1548                         '$map_text' => DI::l10n()->t('Map'),
1549                         '$likebuttons' => $likebuttons,
1550                         '$like' => $like,
1551                         '$dislike' => $dislike,
1552                         '$comments' => $comments,
1553                         '$paginate' => $paginate,
1554                 ]);
1555
1556                 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1557                 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1558                 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1559                 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1560                 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1561
1562                 return $o;
1563         }
1564
1565         // Default - show recent photos with upload link (if applicable)
1566         //$o = '';
1567         $total = 0;
1568         $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1569                 $sql_extra GROUP BY `resource-id`",
1570                 intval($user['uid']),
1571                 DBA::escape(Photo::CONTACT_PHOTOS),
1572                 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1573         );
1574         if (DBA::isResult($r)) {
1575                 $total = count($r);
1576         }
1577
1578         $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1579
1580         $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1581                 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1582                 ANY_VALUE(`created`) AS `created` FROM `photo`
1583                 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1584                 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1585                 intval($user['uid']),
1586                 DBA::escape(Photo::CONTACT_PHOTOS),
1587                 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1588                 $pager->getStart(),
1589                 $pager->getItemsPerPage()
1590         );
1591
1592         $photos = [];
1593         if (DBA::isResult($r)) {
1594                 // "Twist" is only used for the duepunto theme with style "slackr"
1595                 $twist = false;
1596                 foreach ($r as $rr) {
1597                         //hide profile photos to others
1598                         if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1599                                 continue;
1600                         }
1601
1602                         $twist = !$twist;
1603                         $ext = $phototypes[$rr['type']];
1604
1605                         $alt_e = $rr['filename'];
1606                         $name_e = $rr['album'];
1607
1608                         $photos[] = [
1609                                 'id'    => $rr['id'],
1610                                 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1611                                 'link'  => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1612                                 'title' => DI::l10n()->t('View Photo'),
1613                                 'src'   => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1614                                 'alt'   => $alt_e,
1615                                 'album' => [
1616                                         'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1617                                         'name' => $name_e,
1618                                         'alt'  => DI::l10n()->t('View Album'),
1619                                 ],
1620
1621                         ];
1622                 }
1623         }
1624
1625         $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1626         $o .= Renderer::replaceMacros($tpl, [
1627                 '$title' => DI::l10n()->t('Recent Photos'),
1628                 '$can_post' => $can_post,
1629                 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1630                 '$photos' => $photos,
1631                 '$paginate' => $pager->renderFull($total),
1632         ]);
1633
1634         return $o;
1635 }