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