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