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