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