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